Soul.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 altitude;
  16. public Transform target;
  17. private void Awake()
  18. {
  19. SoulInMap.souls.Add(this);
  20. }
  21. public void Burst(Vector3 velocity)
  22. {
  23. rb.isKinematic = false;
  24. rb.velocity = velocity;
  25. collected = false;
  26. }
  27. public async void BeCollect(int id)
  28. {
  29. rb.isKinematic = true;
  30. collected = true;
  31. tweenPos.from = transform;
  32. tweenPos.to = PlayersInput.instance[id].transform;
  33. tweenPos.duration = (tweenPos.from.position - tweenPos.to.position).magnitude / flySpeed;
  34. tweenPos.ResetToBeginning();
  35. tweenPos.PlayForward();
  36. await Task.Delay((int)(tweenPos.duration * 1000));
  37. BeGet(id);
  38. SoulInMap.souls.Remove(this);
  39. gameObject.SetActive(false);
  40. }
  41. public void BeGet(int id)
  42. {
  43. PlayersInput.instance[id].mp += addMp;
  44. }
  45. private void FixedUpdate()
  46. {
  47. if(transform.position.y>= altitude)
  48. {
  49. rb.velocity = Vector3.zero;
  50. }
  51. else
  52. {
  53. Vector3 velocity = rb.velocity;
  54. velocity.y = upSpeed;
  55. rb.velocity = velocity;
  56. }
  57. }
  58. }