diff options
Diffstat (limited to 'ActiveRagdoll/Assets/Scripts/SyncTransform.cs')
-rw-r--r-- | ActiveRagdoll/Assets/Scripts/SyncTransform.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/ActiveRagdoll/Assets/Scripts/SyncTransform.cs b/ActiveRagdoll/Assets/Scripts/SyncTransform.cs new file mode 100644 index 0000000..8ebf2e0 --- /dev/null +++ b/ActiveRagdoll/Assets/Scripts/SyncTransform.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[ExecuteInEditMode] +public class SyncTransform : MonoBehaviour +{ + [Flags] + public enum ESyncTransfom + { + Position, + Rotation, + Scale, + RotationY, + } + + public ESyncTransfom syncMode; + + public Transform target; + + void Update() + { + if(syncMode.HasFlag(ESyncTransfom.Position)) + { + transform.position = Vector3.Lerp(transform.position, target.position, 0.2f); + } + + if(syncMode.HasFlag(ESyncTransfom.Rotation)) + { + transform.rotation = target.rotation; + } + + if(syncMode.HasFlag(ESyncTransfom.Scale)) + { + transform.localScale = target.localScale; + } + + if(syncMode.HasFlag(ESyncTransfom.RotationY)) + { + Quaternion rot = target.rotation; + Vector3 angle = rot.ToEuler(); + transform.rotation = Quaternion.Euler(0, -90, 0)*Quaternion.Euler(0, angle.y, 0); + } + } + +} |