// Update is called once per frame void Update() { Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, interactRange); //see if this hits any interactive object if (hit.transform) { //Debug.Log(hit.transform.name); interactiveObject = hit.transform.GetComponent <InteractiveObject>(); } else { interactiveObject = null; } reticleController.ShowIcon(interactiveObject); if (Input.GetKeyDown(KeyCode.E)) { if (interactiveObject) { // object is a door/drawer interactiveObject.onObjectInteraction(); } } }
void Update() { Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, interactiveRange); if (hit.transform) { interactiveObject = hit.transform.GetComponent <InteractiveObject>(); } else { interactiveObject = null; } reticleController.ShowIcon(interactiveObject); if (Input.GetKeyDown(KeyCode.E)) { if (interactiveObject) { interactiveObject.PerformAction(); } } }