MegaHoseNewAttach.cs 833 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using UnityEngine;
  2. [ExecuteInEditMode]
  3. [AddComponentMenu("MegaShapes/Hose New Attach")]
  4. public class MegaHoseNewAttach : MonoBehaviour
  5. {
  6. public float alpha = 0.0f;
  7. public MegaHoseNew 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. }