private void Start() { _startPosition = Player.transform.position; _magicRb = magic.GetComponent <Rigidbody>(); GenerateWorld.RunDummy(); Dead = false; _livesLeft = PlayerPrefs.GetInt(PlayerPrefKeys.Lives); UpdateLivesLeftUI(); }
private void OnTriggerEnter([NotNull] Collider other) { // Boxes mark spawning points. // We need to prevent spawning new instances in front of us when exiting into a T-section. // We're handling this special case in the movement (rotation) code. if (other is BoxCollider && !GenerateWorld.LastPlatform.CompareTag("platformTSection")) { GenerateWorld.RunDummy(); } // Spheres mark turning points. if (other is SphereCollider) { _canTurn = true; } }
private void Update() { if (Dead) { return; } if (CurrentPlatform != null) { // Make the player appear falling immediately. const float shortFallingDistance = 2f; if (transform.position.y < CurrentPlatform.transform.position.y - shortFallingDistance) { _anim.SetTrigger(IsFalling); } const float fallingDistance = 10f; if (transform.position.y < CurrentPlatform.transform.position.y - fallingDistance) { _falling = true; // Trigger the restarting and everything. OnCollisionEnter(null); return; } } var rotateDown = Input.GetButtonDown("Rotate"); var rotate = Input.GetAxisRaw("Rotate") * (rotateDown ? 1 : 0); var shiftDown = Input.GetButtonDown("Horizontal"); var shift = Input.GetAxisRaw("Horizontal") * (shiftDown ? 1 : 0); var delayedDummySpawn = false; if (Input.GetButtonDown("Jump")) { _anim.SetBool(IsJumping, true); GameData.Singleton.SoundJump.Play(); _rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); } else if (Input.GetButtonDown("Fire1")) { _anim.SetBool(IsMagic, true); } else if (rotate > 0 && _canTurn) { transform.Rotate(Vector3.up * 90); GameData.Singleton.SoundWhoosh.Play(); delayedDummySpawn = true; } else if (rotate < 0 && _canTurn) { transform.Rotate(Vector3.up * -90); GameData.Singleton.SoundWhoosh.Play(); delayedDummySpawn = true; } else if (shift > 0) { transform.Translate(0.5f, 0, 0); } else if (shift < 0) { transform.Translate(-0.5f, 0, 0); } if (!delayedDummySpawn) { return; } var tf = transform; GenerateWorld.DummyTraveller.transform.forward = -tf.forward; GenerateWorld.RunDummy(); // Build more platforms into the future, unless we just generated a T-section if (!GenerateWorld.LastPlatform.CompareTag("platformTSection")) { GenerateWorld.RunDummy(); } transform.position = new Vector3(_startPosition.x, tf.position.y, _startPosition.z); }