Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- //The shrine of time is an object in the scene that the player can activate to start a time trial.
- public class ShrineOfTime : MonoBehaviour
- {
- //Turning variable for animation
- private const string Turning = "Turning";
- private static int TurningId = 0;
- [SerializeField] private Animator _animator = null;
- [SerializeField] private float _defaultRecordTime = 3000;
- //Player
- private bool _playerIn;
- private void Awake()
- {
- TurningId=Animator.StringToHash(Turning);
- _animator.SetBool(TurningId,false);
- }
- private void Start()
- {
- //If level hasn't been beaten before or time trial mode is already active, then the shrine needs to be hidden
- if (!GameManager.HasBeatenCurrentLevel() || GameManager.TimeTrialMode)
- {
- gameObject.SetActive(false);
- }
- }
- //Update when player can trigger the shrine
- private IEnumerator PlayerInUpdate()
- {
- //If player is already in, then this update is running already
- if (_playerIn) yield break;
- _playerIn = true;
- while (_playerIn)
- {
- if (InputManager.InteractDown())
- {
- GameManager.StartTimeTrial(_defaultRecordTime);
- }
- yield return null;
- }
- }
- public void OnTriggerEnter(Collider other)
- {
- var playerScript = other.GetComponent<Player>();
- if (playerScript != null)
- {
- //Player entered. Start update and make the hourglass turn
- StartCoroutine(PlayerInUpdate());
- _animator.SetBool(TurningId, true);
- }
- }
- public void OnTriggerExit(Collider other)
- {
- var playerScript = other.GetComponent<Player>();
- if (playerScript != null)
- {
- //Player left. Stop the hourglass from turning
- _playerIn = false;
- _animator.SetBool(TurningId, false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement