informatica:realidad_virtual:unity:puzzle
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| informatica:realidad_virtual:unity:puzzle [2023/01/31 17:05] – jose | informatica:realidad_virtual:unity:puzzle [2023/01/31 17:21] (current) – jose | ||
|---|---|---|---|
| Line 15: | Line 15: | ||
| {{: | {{: | ||
| + | |||
| + | Ahora creamos los scripts. Creamos una carpeta en Assets que se llame scripts. Dentro de esa carpeta, botón derecho y " | ||
| + | |||
| + | El contenido del Script es el siguiente (tened en cuenta que el nombre del script es la clase principal) | ||
| + | |||
| + | < | ||
| + | using UnityEngine; | ||
| + | using UnityEngine.Events; | ||
| + | using UnityEngine.XR.Interaction.Toolkit; | ||
| + | |||
| + | |||
| + | public class EncajarFoto : MonoBehaviour | ||
| + | { | ||
| + | [SerializeField] private Transform CorrectPuzzlePiece; | ||
| + | private XRSocketInteractor socket; | ||
| + | |||
| + | [Header(" | ||
| + | public UnityEvent onPuzzleCompletion; | ||
| + | | ||
| + | private void Awake() => socket = GetComponent< | ||
| + | | ||
| + | private void OnEnable() | ||
| + | { | ||
| + | socket.selectEntered.AddListener(ObjectSnapped); | ||
| + | } | ||
| + | |||
| + | private void OnDisable() | ||
| + | { | ||
| + | socket.selectEntered.RemoveListener(ObjectSnapped); | ||
| + | } | ||
| + | |||
| + | private void ObjectSnapped(SelectEnterEventArgs arg0) | ||
| + | { | ||
| + | var snappedObjectName = arg0.interactableObject; | ||
| + | if(snappedObjectName.transform.name == CorrectPuzzlePiece.name) | ||
| + | { | ||
| + | onPuzzleCompletion.Invoke(); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Arrastramos el script a " | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Aquí tenemos la variable " | ||
| + | |||
| + | Arrastramos nuestra foto a " | ||
| + | |||
| + | {{: | ||
| + | |||
informatica/realidad_virtual/unity/puzzle.1675184749.txt.gz · Last modified: by jose
