Switching cameras


I need to switch between several cameras. I have a mainCamera attached to the Player and several cameras that I need to activate when the Player is in front of a supermarket shelf.

My code to “Activate” the shelf view is working fine, the problem is that activates always the same camera, the one of the first shelf.

Here is my code to “activate” the shelf view:

var mainCamera : Camera;

private var cameraRayLenght : float = 0.5;
private var estanteTag : String = "estante";
private var players : GameObject;

    function Update () {
    	players = GameObject.FindWithTag("Player");
    	var hit : RaycastHit;
    	if(Physics.Raycast(transform.position, transform.forward, hit, cameraRayLenght))
    		var hitt = hit.transform;
    		if(hitt.tag == estanteTag) {
    			if(Input.GetKeyDown("q")) {
    	Debug.DrawRay (transform.position, transform.forward* cameraRayLenght, Color.green);
    function ActivateEstante(hitt : Transform) {
    	mainCamera.enabled = false;
    	hitt.camera.enabled = true;
    	players.active = false;

Check your colliders. Make sure the first shelf’s is not overlapping the others.