summaryrefslogtreecommitdiff
path: root/ExampleWheelController.cs
diff options
context:
space:
mode:
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));
+ }
+ }
+}