// Start is called before the first frame update private void Awake() { Debug.Log("Inventory"); instence = this; OnItemClickEvent += UseItem; }
void Update() { // Set origin of ray to 'center of screen' and direction of ray to 'cameraview' Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0F)); RaycastHit hit; // Variable reading information about the collider hit // Cast ray from center of the screen towards where the player is looking if (Physics.Raycast(ray, out hit, Reach)) { if (hit.collider.tag == "Door") { InReach = true; // Display the UI element when the player is in reach of the door if (TextActive == false && TextPrefab != null) { TextPrefabInstance = Instantiate(TextPrefab); TextActive = true; TextPrefabInstance.transform.SetParent(transform, true); // Make the player the parent object of the text element } // Give the object that was hit the name 'Door' Door = hit.transform.gameObject;; g0 = gameObject; Invantory inv = gameObject.GetComponent <Invantory>(); if (!inv.objectsInInvantory.Contains(RequiredItem)) { return; } // Get access to the 'Door' script attached to the object that was hit Door dooropening = Door.GetComponent <Door>(); if (Input.GetKey(Character)) { // Open/close the door by running the 'Open' function found in the 'Door' script if (dooropening.RotationPending == false) { StartCoroutine(hit.collider .GetComponent <Door>() .Move()); StartCoroutine(hit.collider .GetComponent <Door>() .DoPlayerWinning()); } } } else { InReach = false; // Destroy the UI element when Player is no longer in reach of the door if (TextActive == true) { DestroyImmediate(TextPrefabInstance); TextActive = false; } } } else { InReach = false; // Destroy the UI element when Player is no longer in reach of the door if (TextActive == true) { DestroyImmediate(TextPrefabInstance); TextActive = false; } } //Draw the ray as a colored line for debugging purposes. Debug.DrawRay(ray.origin, ray.direction * Reach, DebugRayColor); }