| | | 1 | | using System; |
| | | 2 | | using System.Collections; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using UnityEngine; |
| | | 5 | | using UnityEngine.XR.Interaction.Toolkit; |
| | | 6 | | public class finalPuzzleSockets : MonoBehaviour |
| | | 7 | | { |
| | | 8 | | [SerializeField] private finalPuzzle linkedPuzzleManager; |
| | | 9 | | |
| | | 10 | | private XRSocketInteractor socket; |
| | | 11 | | |
| | | 12 | | [SerializeField] private Transform secondPartCorrect; |
| | | 13 | | |
| | 3 | 14 | | private void Awake() => socket = GetComponent<XRSocketInteractor>(); |
| | | 15 | | |
| | | 16 | | private void OnEnable() |
| | 3 | 17 | | { |
| | 3 | 18 | | if (socket == null) |
| | 0 | 19 | | { |
| | 0 | 20 | | socket = GetComponent<XRSocketInteractor>(); |
| | 0 | 21 | | } |
| | 3 | 22 | | if (socket != null) |
| | 3 | 23 | | { |
| | 3 | 24 | | socket.selectEntered.AddListener(ObjectSnapped); |
| | 3 | 25 | | socket.selectExited.AddListener(ObjectRemoved); |
| | 3 | 26 | | } |
| | 3 | 27 | | } |
| | | 28 | | |
| | | 29 | | private void OnDisable() |
| | 3 | 30 | | { |
| | 3 | 31 | | socket.selectEntered.RemoveListener(ObjectSnapped); |
| | 3 | 32 | | socket.selectExited.RemoveListener(ObjectRemoved); |
| | 3 | 33 | | } |
| | | 34 | | |
| | | 35 | | private void ObjectSnapped(SelectEnterEventArgs arg0) |
| | 3 | 36 | | { |
| | 3 | 37 | | linkedPuzzleManager.incrementFirstPart(); |
| | 3 | 38 | | if (arg0.interactableObject.transform.name == secondPartCorrect.name) |
| | 0 | 39 | | { |
| | 0 | 40 | | linkedPuzzleManager.incrementSecondPart(); |
| | 0 | 41 | | } |
| | 3 | 42 | | } |
| | | 43 | | private void ObjectRemoved(SelectExitEventArgs arg0) |
| | 0 | 44 | | { |
| | 0 | 45 | | linkedPuzzleManager.decrementFirstPart(); |
| | 0 | 46 | | if (arg0.interactableObject.transform.name == secondPartCorrect.name) |
| | 0 | 47 | | { |
| | 0 | 48 | | linkedPuzzleManager.decrementSecondPart(); |
| | 0 | 49 | | } |
| | 0 | 50 | | } |
| | | 51 | | } |