camera on trigger??

hey guys i have a question if i want to view camera2 when trigger gets collided with enything in the sene so it will switch to camera2 i think the script i need is somthing like this.

Function OntriggerEnter (Collission.Collider); {
Camera2 render.renderer = true;
}

does this do what i want i think so but you see i probely know what i shoud type in the script onley i dont know exactly with all the points and dots and brekkets so can you help me out thanks

Instead of having multiple cameras I would just change the position of the main camera upon entering the trigger.

Setup

  1. Make sure you camera is tagged as "MainCamera".
  2. Create an empty gameobject
  3. Position and rotate the gameobject to the position you want your camera to appear in
  4. Add a collider to the empty gameobject and scale/position it. Tick the isTrigger box.
  5. Create a new javascript with the code below and attach it to the empty gameObject.

    var mainCam : GameObject;

    function Awake() { //set the mainCam variable to the MainCamera mainCam = GameObject.FindWithTag("MainCamera"); }

    function OnTriggerEnter (other : Collider) { //check that the player has entered the trigger and not an enemy/other object if (other.tag == "Player") { //set the position of the camera to the current game objects position mainCam.transform.position = transform.position; //set the rotation of the camera to that of the game object rotation mainCam.transform.rotation = transform.rotation; } }

The camera component can be enabled or disabled like this (without accessing the collisionInfo):

function OntriggerEnter () {
  Camera2.enabled = true;
}