PickUp.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. using System;
  6. using UnityEngine.AI;
  7. public class PickUp : MonoBehaviour
  8. {
  9. public enum PickUpType
  10. {
  11. Baloon,
  12. Heart,
  13. Fall,
  14. Candy,
  15. Cristal,
  16. Jump,
  17. Rock
  18. }
  19. public PickUpType CurPickUpType;
  20. public Vector3 SatrtPosition;
  21. public Quaternion SatrtRotation;
  22. private Transform StartParent;
  23. void Awake()
  24. {
  25. SatrtPosition = transform.position;
  26. SatrtRotation = transform.rotation;
  27. StartParent = transform.parent;
  28. }
  29. public void ResetPickUp()
  30. {
  31. transform.position = SatrtPosition;
  32. transform.SetParent(StartParent);
  33. transform.gameObject.SetActive(true);
  34. transform.localScale = Vector3.one;
  35. transform.rotation = SatrtRotation;
  36. transform.GetComponent<Collider>().enabled = true;
  37. }
  38. private void OnTriggerEnter(Collider other)
  39. {
  40. //Debug.Log(other.tag);
  41. if (other.tag == "Player")
  42. {
  43. switch(CurPickUpType)
  44. {
  45. case PickUpType.Baloon:
  46. Debug.Log("Baloon");
  47. other.GetComponent<RunnersController>().FlyPlayer();
  48. other.GetComponent<RunnersController>().Agent.speed *= 1.3f;
  49. GetComponent<Collider>().enabled = false;
  50. transform.SetParent(other.transform);
  51. transform.localPosition = Vector3.zero + Vector3.up*2;
  52. StartCoroutine(FlyWithBaloon(other));
  53. //gameObject.SetActive(false);
  54. break;
  55. case PickUpType.Heart:
  56. if(other.GetComponent<RunnersController>().IsPlayer)
  57. {
  58. Core.Instance.SetHeart();
  59. }
  60. UIManager.Instance.UpdateGameplayMenu();
  61. transform.DOScale(0, 0.5f);
  62. transform.DOLocalMove(transform.localPosition + Vector3.up*2, 0.5f).OnComplete(() => {
  63. transform.DOScale(0, 0.5f).OnComplete(() => {
  64. gameObject.SetActive(false);
  65. });
  66. });
  67. break;
  68. case PickUpType.Cristal:
  69. Core.Instance.SetCristal();
  70. UIManager.Instance.UpdateGameplayMenu();
  71. transform.DOScale(0, 0.5f);
  72. transform.DOLocalRotate(transform.rotation * Vector3.up, 2);
  73. transform.DOLocalMove(transform.localPosition + Vector3.up * 3, 1f).OnComplete(() => {
  74. transform.DOScale(0, 1f).OnComplete(() => {
  75. gameObject.SetActive(false);
  76. });
  77. });
  78. break;
  79. case PickUpType.Candy:
  80. //other.GetComponent<RunnersController>().FlyPlayer();
  81. other.GetComponent<RunnersController>().Agent.speed*= 1.3f;
  82. transform.DOScale(0, 0.5f);
  83. transform.DOLocalMove(transform.localPosition + Vector3.up*2, 0.5f).OnComplete(() => {
  84. transform.DOScale(0, 0.5f).OnComplete(() => {
  85. gameObject.SetActive(false);
  86. });
  87. });
  88. break;
  89. case PickUpType.Fall:
  90. other.GetComponent<RunnersController>().FallPlayer();
  91. other.GetComponent<RunnersController>().enabled = false;
  92. other.GetComponent<SwipeMove>().enabled = false;
  93. other.GetComponent<NavMeshAgent>().enabled = false;
  94. other.GetComponent<Collider>().enabled = false;
  95. //transform.DOScale(0, 0.5f);
  96. //transform.DOLocalMove(transform.localPosition + Vector3.up * 2, 0.5f).OnComplete(() => {
  97. // transform.DOScale(0, 0.5f).OnComplete(() => {
  98. // gameObject.SetActive(false);
  99. // });
  100. //});
  101. break;
  102. case PickUpType.Rock:
  103. other.GetComponent<RunnersController>().Agent.speed *= 0.7f;
  104. other.GetComponent<RunnersController>().Stumble();
  105. //other.GetComponent<RunnersController>().enabled = false;
  106. //other.GetComponent<SwipeMove>().enabled = false;
  107. //other.GetComponent<NavMeshAgent>().enabled = false;
  108. //other.GetComponent<Collider>().enabled = false;
  109. break;
  110. }
  111. }
  112. }
  113. private IEnumerator FlyWithBaloon(Collider other)
  114. {
  115. other.GetComponent<NavMeshAgent>().baseOffset = 2;
  116. yield return new WaitForSeconds(3);
  117. transform.DOScale(0, 0.5f);
  118. other.GetComponent<NavMeshAgent>().baseOffset = 0;
  119. }
  120. public void Update()
  121. {
  122. switch(CurPickUpType)
  123. {
  124. case PickUpType.Baloon:
  125. //transform.DOLocalMoveY(Vector3.forward, -80 * Time.deltaTime);
  126. break;
  127. case PickUpType.Heart:
  128. transform.Rotate(Vector3.forward, -100 * Time.deltaTime);
  129. break;
  130. case PickUpType.Fall:
  131. //transform.Rotate(Vector3.forward, -100 * Time.deltaTime);
  132. break;
  133. case PickUpType.Candy:
  134. transform.Rotate(Vector3.forward, -100 * Time.deltaTime);
  135. break;
  136. case PickUpType.Jump:
  137. //transform.Rotate(Vector3.forward, -100 * Time.deltaTime);
  138. break;
  139. case PickUpType.Cristal:
  140. transform.Rotate(Vector3.forward, -100 * Time.deltaTime);
  141. break;
  142. }
  143. }
  144. }