From a9ccdb31619bbabbfa60550fc6e5191aefaca17c Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 18 Oct 2023 20:51:21 +0800 Subject: + TABG --- ActiveRagdoll/Assets/Scripts/SyncTransform.cs | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ActiveRagdoll/Assets/Scripts/SyncTransform.cs (limited to 'ActiveRagdoll/Assets/Scripts/SyncTransform.cs') 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); + } + } + +} -- cgit v1.1-26-g67d0