I created a script that shows a particular crosshair when the player looks at a openable door. But there is a problem: in my scene there are two doors with the same script, but only if the player looks one of these doors then the crosshair will be enabled.
I put only the void with this function:
void Update ()
{
RaycastHit hit;
ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
Crosshair_Changes scriptCam = Camera.main.GetComponent<Crosshair_Changes> ();
if (interaction == true && Physics.Raycast (ray, out hit) && animationStop == true && hit.transform.name == name)
{
scriptCam.ViewOpenableDoor ();
if (locked == false)
{
if (Input.GetKeyDown ("e"))
{
changeDoorState ();
}
}
else if (locked == true && isBreaking == false)
{
if (Input.GetKeyDown ("e"))
{
}
}
else if (locked == true && isBreaking == true)
{
if (Input.GetKeyDown ("e"))
{
Breaking_Rotating_Handle breakScript = handle.GetComponent<Breaking_Rotating_Handle> ();
breakScript.breakHandle ();
}
}
}
else
{
scriptCam.StopViewOpenableDoor ();
}
}
This script is attached to the doors, instead the void OnGUI () is located in another script attached to the camera.
I don’t undestand what is the problem.