What you will learn in this Unity Tutorial
In this Camera Switching tutorial I’ll go over how to create some code with Javascript which, when the user clicks on a button or object, the view changes to the appropriate camera. This can be useful for switching cameras to the user while playing an Unity game.




First!
Nice, this was much needed.
why do you have to type gameObject in Camera.main.gameObeject.active or overs, what it does ?
I’m actually not 100% sure if this also works by just calling it on a Component directly, but if it does it’s implicit. This way it’s absolutely clear in the code that you’re making the entire GameObject active or non-active; not just a component.
-Patrick
Thanks for the tip!
The funny thing is, that i thought about it earlier today, if this is possible in unity^^
Heh, I can tell you know pretty much anything’s possible; it’s almost always a question of “how”, now “if”.
-Patrick
Great Patrick, just what I have been looking for the last couple of days.
gryff
Hey Patrick, would it be possibly to use one camera and have it lerp to different locations around the scene (to get better transitions)? I mean I know that it is possible, but would you recommend it?
Thanks in Advance
-DH
Hi DH,
Yes, that’s absolutely a good approach! Lerp(), Slerp() and MoveTowards() are great, light-weight functions for tweening and adding motion. =) Nice catch!
-Patrick
Nice tutorial. cgcookie rocks =)
Just a quick suggestion. Since unity allows to build for the web, you could put a build of the tutorials to complement the video.
Hey Carlos,
Thanks for your suggestion! We’d actually talked about this internally a bit some time ago, but I think it sort of slipped into oblivion. I’ll bring this back up again and see what we can do with this. =)
-Patrick
You can use a function with an index too, I dont know the exact info but I have seen alot of scripts with a index. That way it’s really easy.
would you plz make a tut on how to drag and drop a gameobject with the mouse??
I can’t find a good solution that I understand on the web…
-bert
cool man thx
Though I would mention here that every camera has to be tagged to “MainCamera”. Spent a lot of time just struggling and wondering what’s wrong with my script, then I noticed that every time you make a camera in Unity it’s tag is “Untagged”.
Thanks man, that saved me
thanks man!!! omg