Question by
Hunika124 · Jan 28 at 10:02 PM ·
scripting problemscript.scripting beginnervehicle
Reseting rotation of camera
Hi! I have a script and I dont know how to do that idea.
Now if I exit the vehicle (the vehicle is on the side) the camera rotates to the rotation that the vehicle has.
So the idea is, if I press "e" (exit the vehicle) the camera rotation is resets.
The script:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.Vehicles.Car;
public class carManager : MonoBehaviour {
public Camera carCam;
public CarUserControl userCtrl;
private bool inVeh;
private GameObject player;
void Start()
{
userCtrl.enabled = false;
carCam.enabled = false;
inVeh = false;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
if (inVeh == true)
{
vehicleControl(null);
}
}
}
public void vehicleControl(GameObject playerObj)
{
if (inVeh == false)
{
player = playerObj;
carCam.enabled = true;
userCtrl.enabled = true;
player.SetActive(false);
player.transform.parent = this.transform;
StartCoroutine(Time(true));
}
else
{
player.SetActive(true);
carCam.enabled = false;
userCtrl.enabled = false;
player.transform.parent = null;
player = null;
StartCoroutine(Time(false));
}
}
private IEnumerator Time(bool inVehicle)
{
yield return new WaitForSeconds(1);
inVeh = inVehicle;
}
}
Thanks and sorry for the bad english :D
Comment