turning off the game's camera?

hey guys, its been quiet a while since i been here , and i finaly start thinking that i was getting into the scripiting and i could now move on without having to ask you guys everty secound what to do, i know thats pretty anoying and lame …

but… yea… my noobness has come up again…

well… theres a certain point in my game that i want to turn the main camera off, or at least the script attached to that camera to folow the character… so i can

A. make the camera go up to show an arial view of the stage

or

B. just turn the main camera off and turn another camera on, this other camera will be already in place in a higher spot…

but this seems impossible… i made a script attached to the floor… and when the character steps on a pre-defined place… this should happen

GameObject.Find(“MainCamera”).active = false;
GameObject.Find(“ArialCamera”).active = true;

but is not happening >.<… everthing just goes black… and the arial camera never shows up

bellow i can read an error saying "theres no audio listener in the scene "

Hi, if i understand your problem , you want enable and disable the camera.
The code is it :
GameObject.Find(“MainCamera”).enabled= false;
GameObject.Find(“ArialCamera”).enabled= true;

but now it gives me the error saying enabled is not a member of unityengine.gameobject …

killerz’ code is incorrect, but I imagine this:

GameObject.Find("MainCamera").camera.enabled = false;
GameObject.Find("ArialCamera").camera.enabled = true;

Would work, assuming both objects had a camera component attached.

As for why your method didn’t work, I don’t think there’s enough information in your post to say what the problem is. Does the aerial camera work if you test it directly by making it initially active and the other camera initially inactive?

1 Like

yes it does… and yes i think i didnt gave enough info about the scripts… the movement script of my character is based on witch angle the camer is gettting him… like,… if the camera is in his back, then the up arrow is set to move forward… if the camera is cathing him from the front, then down arrow is forward…

so, when i turned the cameras i saw an error aperaring during gameplay, it said " not vector reference " or something like that

but now it works! thanks for the code \o/

GameObject.Find() can only return Active objects, for future reference.

In the original, it never found the “ArialCamera” to turn it on, and turned off the “MainCamera” so there were no active cameras. :slight_smile:
To get round things like this, keep a variable reference. You always have access and its quicker than Find()

ooooohh thats makes perfectly sense!

… so next time i gotta store the arial camera into a var, then i turn this var active right?. thnkz for the tip!