summaryrefslogtreecommitdiff
path: root/ExampleWheelController.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-03-13 11:00:58 +0800
committerchai <215380520@qq.com>2024-03-13 11:00:58 +0800
commit6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch)
treeb38119d2acf0a982cb67e381f146924b9bfc3b3f /ExampleWheelController.cs
+init
Diffstat (limited to 'ExampleWheelController.cs')
-rw-r--r--ExampleWheelController.cs38
1 files changed, 38 insertions, 0 deletions
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<Rigidbody>();
+ 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));
+ }
+ }
+}