ShowVector.cs 889 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using UnityEngine;
  3. public class ShowVector : BaseBehaviour
  4. {
  5. private void Start()
  6. {
  7. this.lastPos = base.transform.position;
  8. }
  9. private void Update()
  10. {
  11. if (this.type == ShowVector.update.Update)
  12. {
  13. this.UpdateVel(Time.smoothDeltaTime);
  14. }
  15. }
  16. private void LateUpdate()
  17. {
  18. if (this.type == ShowVector.update.LateUpdate)
  19. {
  20. this.UpdateVel(Time.deltaTime);
  21. }
  22. }
  23. private void FixedUpdate()
  24. {
  25. if (this.type == ShowVector.update.FixedUpdate)
  26. {
  27. this.UpdateVel(Time.fixedDeltaTime);
  28. }
  29. }
  30. private void UpdateVel(float time)
  31. {
  32. this.vec = base.transform.position - this.lastPos;
  33. this.vec /= time;
  34. this.lastPos = base.transform.position;
  35. }
  36. public Vector3 lastPos;
  37. public Vector3 vec;
  38. public ShowVector.update type;
  39. public enum update
  40. {
  41. Update,
  42. LateUpdate,
  43. FixedUpdate
  44. }
  45. }