mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-27 14:30:17 +00:00
35 lines
No EOL
901 B
C#
35 lines
No EOL
901 B
C#
using UnityEngine;
|
|
|
|
namespace SanAndreasUnity.Behaviours.Vehicles
|
|
{
|
|
[RequireComponent(typeof(Vehicle))]
|
|
public class VehicleController : MonoBehaviour
|
|
{
|
|
private Vehicle _vehicle;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
_vehicle = GetComponent<Vehicle>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!GameManager.CanPlayerReadInput()) return;
|
|
|
|
var accel = Input.GetAxis("Vertical");
|
|
var brake = Input.GetButton("Brake") ? 1.0f : 0.0f;
|
|
var speed = Vector3.Dot(_vehicle.Velocity, _vehicle.transform.forward);
|
|
|
|
if (speed * accel < 0f)
|
|
{
|
|
brake = Mathf.Max(brake, 0.75f);
|
|
accel = 0f;
|
|
}
|
|
|
|
_vehicle.Accelerator = accel;
|
|
_vehicle.Steering = Input.GetAxis("Horizontal");
|
|
_vehicle.Braking = brake;
|
|
}
|
|
}
|
|
} |