ExampleWheelController.cs 1020 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using UnityEngine;
  3. public class ExampleWheelController : MonoBehaviour
  4. {
  5. private void Start()
  6. {
  7. this.m_Rigidbody = base.GetComponent<Rigidbody>();
  8. this.m_Rigidbody.maxAngularVelocity = 100f;
  9. }
  10. private void Update()
  11. {
  12. if (Input.GetKey(KeyCode.UpArrow))
  13. {
  14. this.m_Rigidbody.AddRelativeTorque(new Vector3(-1f * this.acceleration, 0f, 0f), ForceMode.Acceleration);
  15. }
  16. else if (Input.GetKey(KeyCode.DownArrow))
  17. {
  18. this.m_Rigidbody.AddRelativeTorque(new Vector3(1f * this.acceleration, 0f, 0f), ForceMode.Acceleration);
  19. }
  20. float value = -this.m_Rigidbody.angularVelocity.x / 100f;
  21. if (this.motionVectorRenderer)
  22. {
  23. this.motionVectorRenderer.material.SetFloat(ExampleWheelController.Uniforms._MotionAmount, Mathf.Clamp(value, -0.25f, 0.25f));
  24. }
  25. }
  26. public float acceleration;
  27. public Renderer motionVectorRenderer;
  28. private Rigidbody m_Rigidbody;
  29. private static class Uniforms
  30. {
  31. internal static readonly int _MotionAmount = Shader.PropertyToID("_MotionAmount");
  32. }
  33. }