CarController.cs 845 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CarController : MonoBehaviour
  5. {
  6. public Wheel[] turningWheels;
  7. public Wheel[] drivingWheels;
  8. public Rigidbody rb;
  9. public float TopSpeed = 10;
  10. public AnimationCurve PowerCurve;
  11. public float EnginePower = 5;
  12. void Awake(){
  13. foreach(Wheel wheel in turningWheels){
  14. wheel.myCar= this;
  15. }
  16. foreach(Wheel wheel in drivingWheels){
  17. wheel.myCar= this;
  18. }
  19. }
  20. void FixedUpdate()
  21. {
  22. //up or down
  23. foreach(Wheel wheel in drivingWheels){
  24. wheel.Rotate(Input.GetAxis("Vertical"));
  25. }
  26. foreach(Wheel wheel in turningWheels){
  27. wheel.Steer(Input.GetAxis("Horizontal"));
  28. }
  29. }
  30. }