CarUserControl.cs 872 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using UnityEngine;
  3. using UnityStandardAssets.CrossPlatformInput;
  4. namespace UnityStandardAssets.Vehicles.Car
  5. {
  6. [RequireComponent(typeof (CarController))]
  7. public class CarUserControl : MonoBehaviour
  8. {
  9. private CarController m_Car; // the car controller we want to use
  10. private void Awake()
  11. {
  12. // get the car controller
  13. m_Car = GetComponent<CarController>();
  14. }
  15. private void FixedUpdate()
  16. {
  17. // pass the input to the car!
  18. float h = CrossPlatformInputManager.GetAxis("Horizontal");
  19. float v = CrossPlatformInputManager.GetAxis("Vertical");
  20. #if !MOBILE_INPUT
  21. float handbrake = CrossPlatformInputManager.GetAxis("Jump");
  22. m_Car.Move(h, v, v, handbrake);
  23. #else
  24. m_Car.Move(h, v, v, 0f);
  25. #endif
  26. }
  27. }
  28. }