Soul.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 int 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.isKinematic = false;
  46. rb.velocity = velocity;
  47. collected = false;
  48. }
  49. public async void BeCollect(int id)
  50. {
  51. rb.isKinematic = true;
  52. collected = true;
  53. tweenPos.from = transform;
  54. tweenPos.to = PlayersInput.instance[id].transform;
  55. tweenPos.duration = (tweenPos.from.position - tweenPos.to.position).magnitude / flySpeed;
  56. tweenPos.ResetToBeginning();
  57. tweenPos.PlayForward();
  58. await Task.Delay((int)(tweenPos.duration * 1000));
  59. BeGet(id);
  60. SoulInMap.souls.Remove(this);
  61. gameObject.SetActive(false);
  62. }
  63. public void BeGet(int id)
  64. {
  65. if (isSourPurple)
  66. {
  67. spiritSystem.GainNewSpirit(id, type);
  68. }
  69. else
  70. {
  71. PlayersInput.instance[id].mp += addMp;
  72. }
  73. }
  74. private void Update()
  75. {
  76. if (haveTransmit)
  77. {
  78. transmitTime -= Time.deltaTime;
  79. if (transmitTime <= 0)
  80. {
  81. haveTransmit = false;
  82. portalsController.rbs.Remove(rb);
  83. }
  84. }
  85. }
  86. private void FixedUpdate()
  87. {
  88. if (isShoot)
  89. {
  90. time += Time.deltaTime;
  91. transform.position = Vector3.Lerp(from, to, time);
  92. if (Vector3.Distance(transform.position, to)<1f)
  93. {
  94. isShoot = false;
  95. }
  96. }
  97. if(transform.position.y>= altitude)
  98. {
  99. rb.velocity = Vector3.zero;
  100. }
  101. else
  102. {
  103. Vector3 velocity = rb.velocity;
  104. velocity.y = upSpeed;
  105. rb.velocity = velocity;
  106. }
  107. }
  108. public void BeShoot()
  109. {
  110. time = 0;
  111. isShoot = true;
  112. }
  113. }