Hi guys
So I have this script where when the player gets in the Trigger the MainCamera rotates. Of course I want to disable MouseLook and CharacterController so there are no turned around moving. However for some mysterious reason neither of the above mentioned omponents want to get disabled and I have no idea why. I was searching through forums, but didn’t find any answer yet.
Thanks in advance
private var InRange : boolean;
private var mainCam : GameObject;
private var finishedTurning : boolean;
private var startTurning : boolean;
private var player : GameObject;
var hideCam : Camera;
var smooth : float;
function Awake()
{
mainCam = GameObject.FindGameObjectWithTag("MainCamera");
player = GameObject.FindGameObjectWithTag("Player");
}
function OnTriggerEnter (theCollider : Collider)
{
if (theCollider.tag == "Player")
{
InRange = true;
}
}
function OnTriggerExit()
{
InRange = false;
finishedTurning = false;
startTurning = false;
}
function Update()
{
if(startTurning InRange !finishedTurning)
{
mainCam.transform.rotation = Quaternion.Lerp(mainCam.transform.rotation, hideCam.transform.rotation,Time.deltaTime*smooth);
}
if( Mathf.Abs(mainCam.transform.rotation.y-hideCam.transform.rotation.y) < 0.01)
{
finishedTurning = true;
}
if(Input.GetKeyDown(KeyCode.E) InRange)
{
player.GetComponent(CharacterController).enabled = false;
player.GetComponent(MouseLook).enabled = false;
mainCam.GetComponent(MouseLook).enabled = false;
startTurning = true;
}
}