This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
forked from qoopen0815/OcsVehicle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DumpTruckController.cs
48 lines (41 loc) · 1.72 KB
/
DumpTruckController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ocs.Vehicle.Controller
{
public class DumpTruckController : MonoBehaviour
{
[SerializeField] private DumpTruck _vehicle;
private Ocs.Input.VehicleInput _input;
private void Awake()
{
this._input = new Ocs.Input.VehicleInput();
}
private void Start()
{
// Callback
this._input.Car.ShiftUp.started += context => this._vehicle.ReverseGear = false;
this._input.Car.ShiftDown.started += context => this._vehicle.ReverseGear = true;
this._input.Equipment.Light.started += context => this._vehicle.SwitchLight();
this._input.Equipment.Hone.started += context => this._vehicle.PlayHone();
this._input.Equipment.LeftWinker.started += context => this._vehicle.SwitchLeftWinker();
this._input.Equipment.RightWinker.started += context => this._vehicle.SwitchRightWinker();
}
private void OnEnable() => this._input.Enable();
private void OnDestroy() => this._input.Dispose();
private void OnDisable()
{
this._input.Disable();
this._vehicle.AccelInput = 0.0f;
this._vehicle.BrakeInput = 1.0f;
this._vehicle.SteerInput = 0.0f;
}
void Update()
{
this._vehicle.AccelInput = this._input.Car.Accel.ReadValue<float>();
this._vehicle.BrakeInput = this._input.Car.Brake.ReadValue<float>();
this._vehicle.SteerInput = this._input.Car.Steering.ReadValue<Vector2>()[0];
this._vehicle.WorkJointInput = this._input.DumpTruck.Work.ReadValue<float>();
}
}
}