//Setting camera orbit transforms for hide private void Start() { playerPosRef = Camera.main.GetComponent <CamLock>().player.GetComponent <playerPossession>(); CameraTransform = this.transform; //This script should be attached to the camera, so we grab its transform //CameraParent = this.transform.parent; //CREATE NEW EMPTY PIVOT OBJECT AT TARGET HIDE LOCATION }
// Use this for initialization void Start() { // Comments are cool. isStoryboardActive = true; allStoryboardIntro = StoryboardIntro.GetComponentsInChildren <Image>(); allStoryboardOutro = StoryboardOutro.GetComponentsInChildren <Image>(); Cursor.visible = true; Cursor.lockState = CursorLockMode.None; player = GameObject.FindGameObjectWithTag("Player").GetComponent <playerPossession>(); cursor = GameObject.Find("BlackReticle"); screenDimension = new Vector3(Screen.width, Screen.height); cursor.GetComponent <RectTransform>().position = new Vector3(screenDimension.x / 2, screenDimension.y / 2, cursor.GetComponent <RectTransform>().position.z); if (screenDimension.x > 1000) { fontSize = 25; } else { fontSize = 50; } //txt_timerText = GameObject.Find("Timer").GetComponent<Text>(); txt_npcCount = GameObject.Find("NPC's Left").GetComponent <Text>(); //txt_playerHealth = GameObject.Find("Health").GetComponent<Text>(); //player = gameObject.GetComponentInParent<playerController>(); //Load the TextObjects from canvasWinOrLose foreach (RectTransform text in canvasWinOrLose.gameObject.GetComponentsInChildren <RectTransform>(true)) { if (text.name == "WinText") { winText = text; } if (text.name == "LoseText") { loseText = text; } } NavMesh.avoidancePredictionTime = 4f; //Debug.Log(UpdateSensTxt.mouseSensX); Time.timeScale = 0; }
} //End update //void Gameover() //{ // timeLeft = 0; // player.health = 0; // txt_timerText.text = "0:00"; // txt_playerHealth.text = player.health.ToString() + "%"; // //Disable Scripts here // canvasWinOrLose.gameObject.SetActive(true); // loseText.gameObject.SetActive(true); // Time.timeScale = 0; // player.GetComponent<PlayerController>().enabled = false; //} //public void ResumeGameplay() //{ // if (paused == true) // { // canvasPause.gameObject.SetActive(false); // Camera.main.GetComponent<CamLock>().enabled = true; // player.gameObject.GetComponent<playerCannonBall>().enabled = true; // player.gameObject.GetComponent<playerPossession>().enabled = true; // player.gameObject.GetComponent<AudioSource>().enabled = true; // player.gameObject.GetComponent<PlayerController>().enabled = true; // AgentController[] agents = GameObject.FindObjectsOfType<AgentController>(); // foreach (AgentController agent in agents) // agent.gameObject.GetComponent<script_ProtonBeam_v5>().enabled = true; // Time.timeScale = 1; // paused = true; // } //} public void Pause() { pPossession = GameObject.FindGameObjectWithTag("Player").GetComponent <playerPossession>(); if (isPaused == true) { sidReticle.GetComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay; foreach (GameObject g in uiShrinkElements) { g.GetComponent <Text>().fontSize = 50; } Time.timeScale = 1; Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; pPossession.enabled = true; pauseMenu.SetActive(false); controlsMenu.SetActive(false); creditsMenu.SetActive(false); isPaused = false; } else { sidReticle.GetComponent <Canvas>().renderMode = RenderMode.WorldSpace; foreach (GameObject g in uiShrinkElements) { g.GetComponent <Text>().fontSize = 5000; } Cursor.visible = true; Cursor.lockState = CursorLockMode.None; pPossession.enabled = false; pauseMenu.SetActive(true); Time.timeScale = 0; isPaused = true; } }
public bool isInLineOfSight() //Adjusted to now only look for the "possessed item" instead of always sid { //Vector3 targetAdjustedPosition = (sid.transform.position + (sid.transform.up * 1.1f)); playerPossession player = sid.GetComponent <playerPossession>(); //Debug.Log(player.PossessedItem.transform.position); Vector3 targetAdjustedPosition = (player.PossessedItem.transform.position + (player.PossessedItem.transform.up * 1.1f)); Vector3 adjustedPosition = (transform.position + (transform.up * 1.4f)); Vector3 direction = targetAdjustedPosition - adjustedPosition; float dot = Vector3.Dot(transform.TransformDirection(Vector3.forward).normalized, direction.normalized); //-1 = directly behind, 1=directly infront //Debug.DrawRay(adjustedPosition, direction, Color.red); //Debug.DrawRay(adjustedPosition, new Vector3(direction.x, direction.y, direction.z + dot)); //If Sid is within the Agent's torch range and angle of the spotlight if (direction.magnitude <= lineOfSight && dot > 0.8f) { //Create a raycast from the AGENT to sid to see if the AGENT has direct line of sight Ray ray = new Ray(adjustedPosition, direction); //-direction RaycastHit[] hits = Physics.RaycastAll(ray, lineOfSight); //Check all the objects within the torch range foreach (RaycastHit hit in hits) { //Looks at all transforms in range and checks for line of sight towards will and whether they are in front of Sid if (hit.distance < direction.magnitude && hit.collider.tag != "Player") { //Debug.DrawRay(adjustedPosition, direction, Color.red); //Draw the ray when another object has been hit that is not the target //Debug.Log(hit.transform.name); return(false); } } //Debug.DrawRay(adjustedPosition, direction, Color.green); //Draw the ray when an object is insde the LOS return(true); } else { return(false); } }
//written by Jak public void Hide() { moveModeActive = false; //Disable camera rotation Camera.main.GetComponent <CamLock>().enabled = false; //This is renabled when the object has stopped moving in update playerPossession possessedItem = target.GetComponent <playerPossession>(); possessedItem.enabled = true; //Enable the item playerPossesion script //Disable movement possessedItem.GetComponent <playerController>().enabled = false; //switch off gravity for the target possessedItem.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; possessedItem.GetComponent <Rigidbody>().drag = 0; //set drag to 0 so item falls like a sack of potatoes without affecting gravity possessedItem.GetComponent <Rigidbody>().angularDrag = 0; possessedItem.GetComponent <Rigidbody>().useGravity = true; possessedItem.GetComponent <Rigidbody>().freezeRotation = true; //Freeze item rotation while possesed, caused the camera to glitch - Jak - 13/11/17 possessedItem.GetComponentInChildren <Renderer>().material.SetFloat("_AuraOnOff", 1); possessedItem.GetComponentInChildren <Renderer>().material.SetColor("_ASEOutlineColor", Color.black); //Camera Pivot setup //Create pivot object for camera orbiting - check when rigidbody is grounded, then add - might need to move this to update function pivot = new GameObject("Pivot"); pivot.transform.position = possessedItem.transform.position; pivot.transform.rotation = possessedItem.transform.rotation; pivot.transform.SetParent(possessedItem.transform); //Child camera to pivot point Camera.main.transform.SetParent(pivot.transform); //Spawn lureSphere if (possessedItem.GetComponent <ItemController>().isScaryObject() && !lureSphereCreated) { Instantiate(lureSphere, possessedItem.transform); lureSphereCreated = true; } //Renable rotation while falling Camera.main.GetComponent <CamLock>().enabled = true; //End Camera Orbit //Change UI GameManager.Instance.EnableHideScaryLure(false); GameManager.Instance.EnableMoveMode(false); if (possessedItem.GetComponent <ItemController>().isScaryObject()) { GameManager.Instance.EnableHideScary(true); } else { GameManager.Instance.EnableHideNonScary(true); } //End UI hidden = true; //set that we are now hidden in an object CamPivotSet = true; }