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(); carrigidbody = GetComponent(); _animator = GetComponent(); firemanControl = GetComponent().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().freezeRotation = false; } void EngineStop() { engineStopped = true; engineStarted = false; this.GetComponent().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; } }