void Update() { // AI, set target if (runAwayDirection == null || tag == "GhostRage") { float distanceToPlayer = Vector3.Distance(transform.position, player.transform.position); bool canSeePlayer = (distanceToPlayer <= TargettingDistance) || tag == "GhostRage"; if (!canSeePlayer && (confiusionTargetTime > Time.timeSinceLevelLoad)) { target = transform.position; } else { bool prevFrameTrackingPlayer = trackingPlayer; if (canSeePlayer) { target = player.transform.position; trackingPlayer = true; } else { target = spawnPoint; trackingPlayer = false; } if (prevFrameTrackingPlayer && !trackingPlayer) { confiusionTargetTime = (Time.timeSinceLevelLoad + Random.Range(2f, 6f)); } } } // Calc direction direction = (runAwayDirection != null) ? (runAwayDirection ?? Vector3.zero) : (transform.position - target); direction.y = 0f; direction *= -1f; // Clear run away dir if (runAwayTimeProgress.IsDone()) { runAwayDirection = null; } // Rotate towards movement direction float directionAngle = Mathf.Atan2(-direction.z, direction.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, directionAngle, 0f); // Check health if (Health < 0f) { if (tag == "GhostRage") { gameManager.GhostDied(); } Instantiate(Explosion, transform.position, Quaternion.identity); Destroy(this.gameObject); } }
void Update() { if (!wasTutorialHidden) { if (Input.GetKeyDown(KeyCode.Space)) { wasTutorialHidden = true; blackScreen.GetComponent <UIImageFader>().FadeOut(10f); tutorialTitle.GetComponent <UITextFader>().FadeOut(10f); tutorialText.GetComponent <UITextFader>().FadeOut(10f); // Kick off the gameplay dialogSystem.ChangeActive(true, "Intro"); } } if (deathScreenTimer.IsDone()) { player.GetComponent <Player>().Respawn(); deathText.GetComponent <UITextFader>().FadeOut(2f); blackScreen.GetComponent <UIImageFader>().FadeOut(2f); deathScreenTimer.Reset(); } if (dialogSystem.HasFinished("Intro")) { postIntroText.GetComponent <UITextFader>().FadeIn(2f); postIntroTimer.Start(7f); } if (postIntroTimer.IsDone()) { postIntroText.GetComponent <UITextFader>().FadeOut(2f); postIntroTimer.Reset(); } if (dialogSystem.HasFinished("BlueFire")) { // Activate new ghosts foreach (GameObject g in rageGhosts) { g.SetActive(true); } Debug.Log("Ghosts to kill " + ghostCount); } // Ending sequence noise.volume = Mathf.Lerp(0.05f, 0f, ending ? 1f : beforeEndingTimer.GetProgress()); if (beforeEndingTimer.IsDone()) { // At this point the screen is black GameObject.Find("Sun").GetComponent <Light>().intensity = 1f; GameObject.Find("Campfire/Point Light").SetActive(false); GameObject.Find("Campfire/Particle System").SetActive(false); player.GetComponent <Player>().Respawn(); player.GetComponent <Player>().MovementEnabled = false; dialogSystem.ChangeActive(true, "Ending"); beforeEndingTimer.Reset(); blackScreen.GetComponent <UIImageFader>().FadeOut(3f); ending = true; } if (dialogSystem.HasFinished("Ending")) { player.GetComponent <Player>().MovementEnabled = false; blackScreen.GetComponent <UIImageFader>().FadeIn(3f); thankYouText.GetComponent <UITextFader>().FadeIn(3f); } }