/// <summary> /// If the GameObject is to the right or left, rotates camera that way, then back once done. /// </summary> /// <param name="hit"></param> /// <returns></returns> IEnumerator RotateAndInteract(GameObject hit) { //Set the initial direction to 0. -2 is left and 2 is right int direction = 0; //Get the relative point of the GameObject var relativePoint = transform.InverseTransformPoint(hit.transform.position); print(relativePoint); //If it is less than -0.2 (set to -0.2 to compensate for any slight errors) if (relativePoint.x < -0.1) { direction = -2; GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Animator>().SetBool("LookLeft", true); yield return(new WaitForSeconds(2)); } //Else if it's more than 0.2 rotate the other way else if (relativePoint.x > 0.1) { direction = 2; GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Animator>().SetBool("LookRight", true); yield return(new WaitForSeconds(2)); } //Do a switch to check what the Player is trying to rotate towards switch (hit.tag) { case "Torch": GameObject lightGameObject = hit.transform.FindChild("Point light").gameObject; if (lightGameObject.GetComponent <Light> ().intensity == 4) { DialogueScript.ErrorText("This light is already fully lit"); } else if (lightGameObject.GetComponent <Light> ().intensity < 4) { lightGameObject.GetComponent <Light> ().intensity = 4; DialogueScript.GameInformationText("You've relit the torch."); LevelScript.RestartTorch(hit.transform.gameObject); lightGameObject.GetComponent <Light> ().intensity = 4; DialogueScript.GameInformationText("The flame seems to burn brighter again."); } yield return(new WaitForSeconds(0.5f)); break; case "Button": //Mark the button as pressed and play the sound and animation for it if (GameObject.Find("Clue").GetComponent <Clue>().FoundPuzzlePiece || SceneManager.GetActiveScene().name == "Tutorial") { hit.transform.GetComponent <Button>().IsPressed = true; hit.transform.GetComponent <AudioSource>().Play(); hit.transform.gameObject.GetComponentInChildren <Animation>().Play(); //Text feedback for the Player DialogueScript.GameInformationText("The button creaks into the wall..."); //Make the LevelScript check if the puzzle is done (i.e. the buttons are pressed). Only if it's not the tutorial. if (SceneManager.GetActiveScene().name != "Tutorial") { LevelScript.CheckPuzzle(); } else if (SceneManager.GetActiveScene().name == "Tutorial") { GameObject.FindGameObjectWithTag("ScriptHolder").GetComponent <Tutorial>().OpenHatch(); } yield return(new WaitForSeconds(0.5f)); break; } DialogueScript.ErrorText("Trying to push the button and failing, you think you are missing something from this dungeon."); yield return(new WaitForSeconds(0.5f)); break; } //Then rotate the camera back the opposite direction of previously if (direction == -2) { GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Animator>().SetBool("LookLeft", false); GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Animator>().SetBool("IdleFromLeft", true); yield return(new WaitForSeconds(2)); GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Animator>().SetBool("IdleFromLeft", false); } else if (direction == 2) { GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Animator>().SetBool("LookRight", false); GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Animator>().SetBool("IdleFromRight", true); yield return(new WaitForSeconds(2)); GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Animator>().SetBool("IdleFromRight", false); } //End movement so the Activation function can continue. MovementHappening = false; }