Looking at other scripts this one should work but it will not change the "state" variable.
I have manually changed this variable in game and the script switches cameras as it should, it just wont do it when I am pushing "e_key"
It shouldn't be a problem as I have doors using the same detection system and they work!
Would be great if anyone could give me a few pointers!
here is the code:
var player_cam : Camera;
var cam : Camera;
var state : int = 0;
function Update ()
{
var hit : RaycastHit;
//find forward then test for x meters in front of position
if (Physics.Raycast (transform.position, transform.forward, hit, 2))
{
if(hit.collider.gameObject.tag=="Player" && Input.GetAxis ("e_key") )
{
if (state == 0)
{
state = 1;
}
if (state == 1)
{
state = 0;
}
}
}
if (state == 1)
{
player_cam.GetComponent("Camera").active = false;
cam.GetComponent("Camera").active = true;
}
if (state == 0)
{
player_cam.GetComponent("Camera").active = true;
cam.GetComponent("Camera").active = false;
}
}