上海虹口龙之梦项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 lines
1.9 KiB

using System;
using UnityEngine;
using System.Collections;
public class CarControl : MonoBehaviour {
private Animator _animator;
public bool openDoor = false;
public bool engineStopped;
public bool engineStarted;
private FiremanControl firemanControl;
private Transform carTransform;
private Rigidbody carrigidbody;
private Vector3 BaseTransform;
private Quaternion BaseRotation;
// Use this for initialization
void Start () {
BaseTransform = this.transform.position;
BaseRotation = this.transform.rotation;
carTransform = GetComponent<Transform>();
carrigidbody = GetComponent<Rigidbody>();
_animator = GetComponent<Animator>();
firemanControl = GetComponent<CarUserControl>().firemanControl;
}
// Update is called once per frame
void Update () {
if (firemanControl.driving)
{
if (Input.GetKeyDown(KeyCode.R)) ResetCarPosition();
}
if ((firemanControl.driving) && (firemanControl.currCar == this.gameObject)&&(!engineStarted)) {
EngineStart();
}
if (engineStarted) {
if((!firemanControl.driving)&&(!engineStopped)){
EngineStop();
}
}
}
void FixedUpdate()
{
_animator.SetBool ("Open", openDoor);
}
void EngineStart(){
engineStopped = false;
engineStarted = true;
this.GetComponent<Rigidbody>().freezeRotation = false;
}
void EngineStop()
{
engineStopped = true;
engineStarted = false;
this.GetComponent<Rigidbody>().freezeRotation = true;
}
void ResetCarPosition()
{
carTransform.position = BaseTransform;
carTransform.rotation = BaseRotation;
//carTransform.eulerAngles = new Vector3(0, carTransform.localEulerAngles.y, 0);
carrigidbody.angularVelocity = Vector3.zero;
carrigidbody.velocity = Vector3.zero;
}
}