Hello.
I’m actually making a game in which there are many cameras, and the switch between them occurs when the player enters a specific trigger. In the actual level I’m working on, I have 9 different cameras.
At first, I did it with Javascript, with the following code :
var cam1 : Camera;
var cam2 : Camera;
function Start() {
cam1.enabled = true;
cam2.enabled = false;
}
function OnTriggerEnter (player : Collider) {
cam1.enabled = !cam1.enabled;
cam2.enabled = !cam2.enabled;
}
It worked perfectly until the gestion of the cameras went wrong. It either chose the wrong one to start, or failed to switch to a camera, even though it worked before. I assumed it was due to Javascript’s instability.I then decided to switch to C# and used this code :
public Camera cam1;
public Camera cam2;
// Use this for initialization
void Start () {
cam1.enabled = true;
cam2.enabled = false;
}
// Update is called once per frame
void Update () {
}
void onTriggerEnter (Collider other) {
if(other.gameObject.tag.Equals("Player")) {
cam1.enabled = !cam1.enabled;
cam2.enabled = !cam2.enabled;
Debug.Log("pass");
}
}
}
Which fails. The trigger detection doesn’t work at all, since the Debug.Log doesn’t. My player has a capsule Collider and a a Rigidbody component. The trigger box has a collider set to “Trigger”. I’m kind of lost since I really don’t know what to do anymore. I searched through answer.unity3d for hours now but can’t find a proper solution.
Thanks for your help !