/// <summary> /// This function is called in Update. /// Used for left mouse button interaction with game objects. Creates a raycast using the mouse position. /// Then uses compareTag() to determine what the obj is. /// /// If its a door... /// If the mouse position is on the door the collider, the door will open or close depending on it's current status. /// The transform (of the door that's being clicked on) being referenced was drag and dropped in the GUI as the reference -- Obtained in line 53 via GetComponent /// /// If its a battery.. /// It increases the light intensity of the flashlight & makes the battery obj inactive /// </summary> void MouseClick() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity)) { Debug.Log("Click!"); if (hit.collider.CompareTag("Door")) { Door_Controller door = hit.transform.GetComponent <Door_Controller>(); if (door) { Debug.Log("Door Click.."); door.MoveDoor(door); } } if (hit.collider.CompareTag("LevelDoor")) { Door_Controller door = hit.transform.GetComponent <Door_Controller>(); if (door) { Debug.Log("LevelDoor Click.."); if (hasKey) { door.MoveDoor(door); } } } if (hit.collider.CompareTag("Battery")) { Debug.Log("Battery Click.."); hit.collider.gameObject.SetActive(false); flash.flashlight.intensity += 1; } if (hit.collider.CompareTag("Light")) { Light_Controller light = hit.transform.GetComponent <Light_Controller>(); Debug.Log("Light Click.."); if (light) { light.setLight(); } } if (hit.collider.CompareTag("Key")) { Debug.Log("Key Click.."); hasKey = true; hit.collider.gameObject.SetActive(false); } } } }
/// <summary> /// When the a door is clicked it will rotate +or- 90 degrees. Depending on if /// it's currently open or closed. Requires a Door_Controller to be passed in so it can access the transform /// of the door and rotate with respect to its current status (open or closed) /// </summary> public void MoveDoor(Door_Controller door) { if (isDoorOpen) { //Works but isn't smooth :( door.transform.Rotate(0f, 90f, 0f); isDoorOpen = false; } else { door.transform.Rotate(0f, -90f, 0f); isDoorOpen = true; } }