diff options
author | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
commit | 6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch) | |
tree | b38119d2acf0a982cb67e381f146924b9bfc3b3f /RotateByKeyboardInput.cs |
+init
Diffstat (limited to 'RotateByKeyboardInput.cs')
-rw-r--r-- | RotateByKeyboardInput.cs | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/RotateByKeyboardInput.cs b/RotateByKeyboardInput.cs new file mode 100644 index 0000000..913473c --- /dev/null +++ b/RotateByKeyboardInput.cs @@ -0,0 +1,103 @@ +using UnityEngine; + +public class RotateByKeyboardInput : MonoBehaviour +{ + public enum XSpace + { + self, + world + } + + public enum YSpace + { + self, + world + } + + public bool useX; + + public XSpace xSpace; + + public Vector3 xVector; + + public bool useY; + + public YSpace ySpace; + + public Vector3 yVector; + + [Header("Control")] + public bool needControl; + + public bool needAlive; + + private HasControl hasControl; + + private PlayerDeath death; + + private float m = 1f; + + private void Start() + { + if (needControl) + { + hasControl = base.transform.root.GetComponent<HasControl>(); + } + if (needAlive) + { + death = base.transform.root.GetComponent<PlayerDeath>(); + } + } + + private void LateUpdate() + { + Vector3 zero = Vector3.zero; + if (Input.GetKey(KeyCode.W)) + { + zero += Vector3.forward; + } + if (Input.GetKey(KeyCode.S)) + { + zero -= Vector3.forward; + } + if (Input.GetKey(KeyCode.D)) + { + zero += Vector3.right; + } + if (Input.GetKey(KeyCode.A)) + { + zero += Vector3.left; + } + zero = zero.normalized; + if (needControl && !hasControl.hasControl) + { + return; + } + if (needAlive) + { + m = Mathf.Clamp(death.muscleFunction * 2f, 0f, 1f); + if (death.dead) + { + return; + } + } + if (useX) + { + Vector3 vector = xVector; + if (xSpace == XSpace.self) + { + vector = base.transform.TransformDirection(vector); + } + base.transform.Rotate(vector * zero.x * m * 0.8f, Space.World); + } + if (useY) + { + Vector3 vector2 = yVector; + if (ySpace == YSpace.self) + { + vector2 = base.transform.TransformDirection(vector2); + } + base.transform.Rotate(vector2 * zero.y * m * 0.8f, Space.World); + } + } +} |