I have a trigger enter that is working bizarrely. The trigger enter is looking to see if the player has entered it and if it does turn a game object on and then off on exit. However, when i start the game it automatically thinks that the player has entered the trigger despite the player being really far away from the trigger. I am good with Unity and scripting, used trigger enter for a lot of things without issue. Here is my code, if anyone can shed some light on this problem that’d be brilliant.
#pragma strict
var securityCameraHolder : GameObject;
var soundActive : boolean = false;
function Start () {
soundActive = false;
}
function OnTriggerEnter (playerEnter : Collider) {
if(playerEnter.gameObject.name == "player");
soundActive = true;
Debug.Log("TriggerEntered");
}
function OnTriggerExit (playerExit : Collider) {
if(playerExit.gameObject.name == "player");
soundActive = false;
Debug.Log("TriggerExit");
}
function Update () {
if(soundActive == true) {
securityCameraHolder.active = true;
Debug.Log("Security Camera is true");
}
if(soundActive == false) {
securityCameraHolder.active = false;
Debug.Log("security camera is false");
}
}