FinishTrigger.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. using System;
  6. public class FinishTrigger : MonoBehaviour
  7. {
  8. public Animator Animator;
  9. public Transform Pivot;
  10. private float normalTime;
  11. public void ResetAnimation()
  12. {
  13. Animator.enabled = false;
  14. Animator.Play("FlyToTower", 0,0);
  15. }
  16. private void OnTriggerEnter(Collider other)
  17. {
  18. if(other.tag == "Player" && !Core.Instance.LevelEnd)
  19. {
  20. if (other.GetComponent<RunnersController>().IsPlayer)
  21. {
  22. normalTime = 0;
  23. other.GetComponent<RunnersController>().enabled = false;
  24. other.GetComponent<RunnersController>().Agent.enabled = false;
  25. other.transform.SetParent(Pivot);
  26. other.transform.DOLocalMove(Vector3.zero, 0.3f);
  27. Animator.enabled = true;
  28. Animator.Play("FlyToTower", 0, normalTime);
  29. Core.Instance.IsGameMode = Core.StateModeGame.Kiss;
  30. //NotificationCenter.Post(NotificationType.GameOver);
  31. //UIManager.Instance.SetTimerKissTower();
  32. StartCoroutine(FlyToTower());
  33. }
  34. else
  35. {
  36. Core.Instance.PlayerGame.Agent.speed = 0;
  37. other.GetComponent<RunnersController>().Agent.enabled = false;
  38. UIManager.Instance.GameOverPanel.gameObject.SetActive(true);
  39. UIManager.Instance.GameOverPanel.DOFade(1, 0.5f);
  40. }
  41. Core.Instance.LevelEnd = true;
  42. other.GetComponent<RunnersController>().SetFlyToTowerAnim();
  43. }
  44. }
  45. private IEnumerator FlyToTower()
  46. {
  47. while(normalTime<=1)
  48. {
  49. normalTime += Time.deltaTime;
  50. yield return new WaitForEndOfFrame();
  51. Animator.SetFloat("NormalizedTime",normalTime);
  52. }
  53. //normalTime = 0;
  54. }
  55. }