*
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
enum ViewMode{
|
||||
Driver,
|
||||
FreeSpectator
|
||||
}
|
||||
|
||||
public class Player : MonoBehaviour {
|
||||
public Car Target;
|
||||
public Camera Cam;
|
||||
public CameraController FlyController;
|
||||
private ViewMode _mode = ViewMode.FreeSpectator;
|
||||
public SteerController steerController;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
SetMode (ViewMode.FreeSpectator);
|
||||
}
|
||||
|
||||
void SetMode(ViewMode mode){
|
||||
if (_mode == mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
_mode = mode;
|
||||
|
||||
if (mode == ViewMode.FreeSpectator) {
|
||||
Cam.transform.parent = null;
|
||||
FlyController.enabled = true;
|
||||
} else {
|
||||
Cam.transform.parent = Target.Driver.transform;
|
||||
Cam.transform.localPosition = Vector3.zero;
|
||||
Cam.transform.localRotation = Quaternion.identity;
|
||||
FlyController.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
if (Target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown (KeyCode.R)) {
|
||||
Target.transform.position = new Vector3(0,3,0);
|
||||
Target.transform.rotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown (KeyCode.Alpha1)) {
|
||||
SetMode(ViewMode.FreeSpectator);
|
||||
}else if (Input.GetKeyDown (KeyCode.Alpha2)) {
|
||||
SetMode(ViewMode.Driver);
|
||||
}
|
||||
|
||||
|
||||
steerController.Steer = Input.GetAxis("Steer");
|
||||
|
||||
|
||||
Target.SetPedalState (CarPedal.Accelerator, (Input.GetAxis ("Axis2") - 1.0f) / -2.0f);
|
||||
Target.SetPedalState (CarPedal.Brake, (Input.GetAxis ("Axis3") - 1.0f) / -2.0f);
|
||||
Target.SetPedalState (CarPedal.Clutch, (Input.GetAxis ("Axis4") - 1.0f) / -2.0f);
|
||||
|
||||
|
||||
|
||||
var ignitionButtons = new KeyCode[]{KeyCode.E, KeyCode.Q};
|
||||
for (int i = 0; i < ignitionButtons.Length; ++i) {
|
||||
if (Input.GetKeyDown (ignitionButtons[i])) {
|
||||
Target.electric.ignition.SetButtonState(i, true);
|
||||
}
|
||||
if (Input.GetKeyUp (ignitionButtons[i])) {
|
||||
Target.electric.ignition.SetButtonState(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
//shift gearbox
|
||||
var gb = Target.transmission.gearbox;
|
||||
var current = gb.Gear;
|
||||
|
||||
if (Input.GetKeyDown (KeyCode.Alpha1)) {
|
||||
current -=1;
|
||||
}else if (Input.GetKeyDown (KeyCode.Alpha2)) {
|
||||
current +=1;
|
||||
}
|
||||
|
||||
current = Mathf.Clamp (current, -1, 5);
|
||||
gb.Gear = current;
|
||||
|
||||
|
||||
//ingition commands
|
||||
/*if (Input.GetKeyDown (KeyCode.Q)) {
|
||||
Target.ignition.Switch(true, false, false);
|
||||
}
|
||||
if (Input.GetKeyUp (KeyCode.Q)) {
|
||||
Target.ignition.Switch(false, false, false);
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown (KeyCode.E)) {
|
||||
Target.ignition.Switch(true, false, true);
|
||||
}
|
||||
if (Input.GetKeyUp (KeyCode.E)) {
|
||||
Target.ignition.Switch(false, false, true);
|
||||
}*/
|
||||
|
||||
/*Cam.transform.position = Target.Driver.transform.position;
|
||||
Cam.transform.rotation = Target.Driver.transform.rotation;*/
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user