x


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

more ▼

asked Apr 11 '11 at 08:16 AM

wesley gravatar image

wesley
48 24 38 46

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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; } }

more ▼

answered Apr 11 '11 at 08:39 AM

GesterX gravatar image

GesterX
2.1k 13 16 37

The code button just is NOT working for me >_<

Apr 11 '11 at 08:43 AM GesterX
(comments are locked)
10|3000 characters needed characters left

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

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

answered Apr 11 '11 at 01:39 PM

efge gravatar image

efge
5.1k 5 14 38

would this not cause an error because your not disabling the 1st camera

Mar 13 '12 at 11:55 AM gochi7
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3001
x984
x72

asked: Apr 11 '11 at 08:16 AM

Seen: 1724 times

Last Updated: Mar 13 '12 at 11:55 AM