Soul.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using UnityEngine;
  5. using uTools;
  6. public class Soul : MonoBehaviour
  7. {
  8. public Rigidbody rb;
  9. public bool collected = false;
  10. public float lerpValue = 0.05f;
  11. public int addMp = 10;
  12. public uTweenPositionTarget tweenPos;
  13. public float flySpeed = 10f;
  14. public float upSpeed = 1;
  15. public float shootSpeed;
  16. public float altitude;
  17. [HideInInspector]
  18. public bool isShoot;
  19. [HideInInspector]
  20. public Vector3 from;
  21. [HideInInspector]
  22. public Vector3 to;
  23. [HideInInspector]
  24. public float time;
  25. public bool Spirits_Invisible_NotFind;
  26. [Header("传送门")]
  27. public bool haveTransmit; //刚传送过
  28. [HideInInspector]
  29. public float transmitTime; //传送CD
  30. public PortalsController portalsController;
  31. [Header("紫魂")]
  32. public bool isSourPurple; //是否是紫魂
  33. public Spirits.SpiritType type;
  34. public SpiritSystem spiritSystem;
  35. private void Awake()
  36. {
  37. spiritSystem = GameObject.Find("SpiritSystem").GetComponent<SpiritSystem>();
  38. if (!isSourPurple)
  39. {
  40. SoulInMap.souls.Add(this);
  41. }
  42. }
  43. public void Burst(Vector3 velocity)
  44. {
  45. rb.velocity = velocity;
  46. collected = false;
  47. }
  48. public async void BeCollect(int id)
  49. {
  50. Spirits spirits = PlayersInput.instance[id].GetComponent<Spirits>();
  51. if (isSourPurple && spirits.hasSpirits == 3)
  52. {
  53. for(int i = 0; i < 3; i++)
  54. {
  55. if(type == spirits.ownSpirits[i])
  56. {
  57. break;
  58. }
  59. if(i == 2)
  60. {
  61. return;
  62. }
  63. }
  64. }
  65. collected = true;
  66. GetComponent<BoxCollider>().enabled = false;
  67. tweenPos.from = transform;
  68. tweenPos.to = PlayersInput.instance[id].transform;
  69. tweenPos.duration = (tweenPos.from.position - tweenPos.to.position).magnitude / flySpeed;
  70. tweenPos.ResetToBeginning();
  71. tweenPos.PlayForward();
  72. await Task.Delay((int)(tweenPos.duration * 1000));
  73. BeGet(id);
  74. SoulInMap.souls.Remove(this);
  75. gameObject.SetActive(false);
  76. }
  77. public void BeGet(int id)
  78. {
  79. if (isSourPurple)
  80. {
  81. spiritSystem.GainNewSpirit(id, type);
  82. }
  83. else
  84. {
  85. PlayersInput.instance[id].mp += addMp;
  86. }
  87. }
  88. private void Update()
  89. {
  90. if (haveTransmit)
  91. {
  92. transmitTime -= Time.deltaTime;
  93. if (transmitTime <= 0)
  94. {
  95. haveTransmit = false;
  96. portalsController.rbs.Remove(rb);
  97. }
  98. }
  99. }
  100. private void FixedUpdate()
  101. {
  102. if (isShoot)
  103. {
  104. time += Time.deltaTime;
  105. transform.position = Vector3.Lerp(from, to, time);
  106. if (Vector3.Distance(transform.position, to)<1f)
  107. {
  108. isShoot = false;
  109. }
  110. }
  111. if(transform.position.y>= altitude)
  112. {
  113. rb.velocity = Vector3.zero;
  114. }
  115. else
  116. {
  117. Vector3 velocity = rb.velocity;
  118. velocity.y = upSpeed;
  119. rb.velocity = velocity;
  120. }
  121. }
  122. public void BeShoot()
  123. {
  124. time = 0;
  125. isShoot = true;
  126. }
  127. }