123456789101112131415161718192021222324252627282930313233 |
- using UnityEngine;
- public class ExampleWheelController : MonoBehaviour
- {
- public float acceleration;
- public Renderer motionVectorRenderer;
- Rigidbody m_Rigidbody;
- static class Uniforms
- {
- internal static readonly int _MotionAmount = Shader.PropertyToID("_MotionAmount");
- }
- void Start()
- {
- m_Rigidbody = GetComponent<Rigidbody>();
- m_Rigidbody.maxAngularVelocity = 100;
- }
- void Update()
- {
- if (Input.GetKey (KeyCode.UpArrow))
- m_Rigidbody.AddRelativeTorque(new Vector3(-1 * acceleration, 0, 0), ForceMode.Acceleration);
- else if (Input.GetKey (KeyCode.DownArrow))
- m_Rigidbody.AddRelativeTorque(new Vector3(1 * acceleration, 0, 0), ForceMode.Acceleration);
- float m = -m_Rigidbody.angularVelocity.x / 100;
- if (motionVectorRenderer)
- motionVectorRenderer.material.SetFloat(Uniforms._MotionAmount, Mathf.Clamp(m, -0.25f, 0.25f));
- }
- }
|