informatica:realidad_virtual:unity:puzzle
This is an old revision of the document!
Puzzle
https://www.youtube.com/watch?v=iSYfs6NXZck
16:15 - Scripts
Se crean las cartas. La caja del puzzle es “XR > Socket Interactor”
Hay que jugar con la orientación. La flecha azul es la que manda. Cuando coges un objeto, lo coge por detrás, es decir, la flecha azul apunta hacía delante de ti y hay que girarlo añadiendo un “GameObject”, girarlo y metiéndolo en Attach transform.
Y así lo metemos en “Attach Transform”
Ahora creamos los scripts. Creamos una carpeta en Assets que se llame scripts. Dentro de esa carpeta, botón derecho y “Create > C# Script”. Lo llamamos “EncajarFoto”
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("Completion Events")] public UnityEvent onPuzzleCompletion; private void Awake() => socket = GetComponent<XRSocketInteractor>(); 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(); } } }
informatica/realidad_virtual/unity/puzzle.1675185398.txt.gz · Last modified: 2023/01/31 17:16 by jose