FollowGameObject.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using UnityEngine;
  3. namespace BasicTools
  4. {
  5. public class FollowGameObject : MonoBehaviour
  6. {
  7. private void Start()
  8. {
  9. }
  10. private void LateUpdate()
  11. {
  12. if (this.Target == null)
  13. {
  14. return;
  15. }
  16. Vector3 b = this.Target.position + this.Offset - base.transform.position;
  17. b = new Vector3(b.x * this.Ignore.x, b.y * this.Ignore.y, b.z * this.Ignore.z);
  18. base.transform.position += b;
  19. }
  20. public FollowGameObject Init(Transform target, Vector3 offset, Vector3 ignore)
  21. {
  22. this.Target = target;
  23. this.Offset = offset;
  24. this.Ignore = ignore;
  25. return this;
  26. }
  27. private Transform Target;
  28. private Vector3 Offset;
  29. private Vector3 Ignore = Vector3.one;
  30. public static class IgnoreParam
  31. {
  32. public static readonly Vector3 X = new Vector3(0f, 1f, 1f);
  33. public static readonly Vector3 Y = new Vector3(1f, 0f, 1f);
  34. public static readonly Vector3 Z = new Vector3(1f, 1f, 0f);
  35. public static readonly Vector3 XY = new Vector3(0f, 1f, 0f);
  36. public static readonly Vector3 YZ = new Vector3(1f, 0f, 0f);
  37. public static readonly Vector3 XZ = new Vector3(0f, 1f, 0f);
  38. }
  39. }
  40. }