From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- ExampleWheelController.cs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ExampleWheelController.cs (limited to 'ExampleWheelController.cs') diff --git a/ExampleWheelController.cs b/ExampleWheelController.cs new file mode 100644 index 0000000..a2f05e0 --- /dev/null +++ b/ExampleWheelController.cs @@ -0,0 +1,38 @@ +using UnityEngine; + +public class ExampleWheelController : MonoBehaviour +{ + private static class Uniforms + { + internal static readonly int _MotionAmount = Shader.PropertyToID("_MotionAmount"); + } + + public float acceleration; + + public Renderer motionVectorRenderer; + + private Rigidbody m_Rigidbody; + + private void Start() + { + m_Rigidbody = GetComponent(); + m_Rigidbody.maxAngularVelocity = 100f; + } + + private void Update() + { + if (Input.GetKey(KeyCode.UpArrow)) + { + m_Rigidbody.AddRelativeTorque(new Vector3(-1f * acceleration, 0f, 0f), ForceMode.Acceleration); + } + else if (Input.GetKey(KeyCode.DownArrow)) + { + m_Rigidbody.AddRelativeTorque(new Vector3(1f * acceleration, 0f, 0f), ForceMode.Acceleration); + } + float value = (0f - m_Rigidbody.angularVelocity.x) / 100f; + if ((bool)motionVectorRenderer) + { + motionVectorRenderer.material.SetFloat(Uniforms._MotionAmount, Mathf.Clamp(value, -0.25f, 0.25f)); + } + } +} -- cgit v1.1-26-g67d0