using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.XR.Interaction.Toolkit; using UnityEngine.XR.Interaction.Toolkit.Interactors; public class Potions : MonoBehaviour { public GameObject[] correctFlasks; public GameObject[] wrongFlasks; private XRSocketInteractor socketInteractor; public Potions potions; public bool taskMessedUp; public AudioSource taskWrongSound; public static int correctPotions = 0; public static bool taskCompletedGlobal = false; void Start() { socketInteractor = GetComponent(); } void OnEnable() { if (socketInteractor != null) { socketInteractor.selectEntered.AddListener(OnSelectEntered); } } void OnDisable() { if (socketInteractor != null) { socketInteractor.selectEntered.RemoveListener(OnSelectEntered); } } public void OnSelectEntered(SelectEnterEventArgs args) { GameObject selectedObject = args.interactableObject.transform.gameObject; if (IsCorrectPotion(selectedObject)) { Debug.Log("Correct potion selected!"); correctPotions++; if (correctPotions == 3) { taskMessedUp = false; correctPotions = 0; taskCompletedGlobal = true; Debug.Log("Task completed!"); } } else if (IsWrongPotion(selectedObject)) { Debug.Log("Wrong potion selected! RUN!!"); taskMessedUp = true; if (!taskWrongSound.isPlaying) { taskWrongSound.Play(); } } } public bool IsCorrectPotion(GameObject obj) { foreach (GameObject correctFlask in correctFlasks) { if (obj == correctFlask) return true; } return false; } public bool IsWrongPotion(GameObject obj) { foreach (GameObject wrongFlask in wrongFlasks) { if (obj == wrongFlask) return true; } return false; } }