1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using UnityEngine;
- [ExecuteInEditMode]
- [AddComponentMenu("MegaShapes/Hose New Attach")]
- public class MegaHoseNewAttach : MonoBehaviour
- {
- public float alpha = 0.0f;
- public MegaHoseNew hose;
- public Vector3 offset = Vector3.zero;
- public Vector3 rotate = Vector3.zero;
- public bool doLateUpdate = true;
- public bool rot = true;
- void Update()
- {
- if ( !doLateUpdate )
- {
- PositionObject();
- }
- }
- void LateUpdate()
- {
- if ( doLateUpdate )
- {
- PositionObject();
- }
- }
- void PositionObject()
- {
- if ( hose )
- {
- Vector3 p1 = hose.GetPosition(alpha);
- if ( rot )
- {
- Vector3 p2 = hose.GetPosition(alpha + 0.001f);
- Quaternion look = Quaternion.LookRotation(p2 - p1) * Quaternion.Euler(rotate);
- transform.rotation = look;
- }
- transform.position = p1 + transform.TransformDirection(offset);
- }
- }
- }
|