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