MegaHoseAttach.cs 782 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 
  2. using UnityEngine;
  3. [ExecuteInEditMode]
  4. public class MegaHoseAttach : MonoBehaviour
  5. {
  6. public float alpha = 0.0f;
  7. public MegaHose hose;
  8. public Vector3 offset = Vector3.zero;
  9. public Vector3 rotate = Vector3.zero;
  10. public bool doLateUpdate = true;
  11. public bool rot = true;
  12. void Update()
  13. {
  14. if ( !doLateUpdate )
  15. {
  16. PositionObject();
  17. }
  18. }
  19. void LateUpdate()
  20. {
  21. if ( doLateUpdate )
  22. {
  23. PositionObject();
  24. }
  25. }
  26. void PositionObject()
  27. {
  28. if ( hose )
  29. {
  30. Vector3 p1 = hose.GetPosition(alpha);
  31. if ( rot )
  32. {
  33. Vector3 p2 = hose.GetPosition(alpha + 0.001f);
  34. Quaternion look = Quaternion.LookRotation(p2 - p1) * Quaternion.Euler(rotate);
  35. transform.rotation = look;
  36. }
  37. transform.position = p1 + transform.TransformDirection(offset);
  38. }
  39. }
  40. }