- Home /
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
Answer by GesterX · Apr 11, 2011 at 08:39 AM
Instead of having multiple cameras I would just change the position of the main camera upon entering the trigger.
Setup
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; } }
Answer by efge · Apr 11, 2011 at 01:39 PM
The camera component can be enabled or disabled like this (without accessing the collisionInfo):
function OntriggerEnter () {
Camera2.enabled = true;
}
would this not cause an error because your not disabling the 1st camera