- Home /
How can I change the camera?
Hi I have a set space, and need to know how I can change the camera by pressing the number 1 and number 2 in C #, I need to Trasnporte by the cameras, and look in different places, thanks. anything else I can put two cameras to the same character?? and to make that change too, say that the front of the camera and the character behind the character. Thanks again.
Answer by CHPedersen · Jun 09, 2011 at 07:40 PM
There were some things in there I had a hard time understanding, but changing cameras is pretty simple, you do so by setting Camera.enabled = true
on the camera you want to start rendering from, and Camera.enabled = false
on all other cameras in your scene. This can be done in few lines of code using the static variable Camera.allCameras which returns an array of all enabled cameras. Disable everything in that array, then reenable the one camera you want to change to.
The last bit you wrote was harder for me to understand, did you mean a kind of rear view camera, sort of like what you do to render content into a rear view mirror in a car racing game?
Answer by juliancruz87 · Jun 09, 2011 at 08:03 PM
Yeah!!!, is for a racing game !!! How can I do it ??
Unity Answers likes to keep posts on a question-answer basis, so folks tend to frown on the posting of additional questions as answers to your original question. :P Try to use comments ins$$anonymous$$d, like this one.
To answer your question, the easiest way is to place a camera at the vehicle's position and point it backwards, then have it render its contents into a RenderTexture. Then you apply that texture to a model of your rear view mirror. This method requires Unity Pro, however.
There is also a more advanced method that involves rendering a silhouette of the rear view mirror into the graphic card's stencil buffer. This results in an image in the stencil buffer that is totally black except for a mirror-shaped "hole" in it, which is totally white. You then render the backwards camera through the stencil, so that it can't render anything except where the stencil has white pixels. This causes it to render its contents into the exact area of the screen where the mirror is located. Think of that as painting on top of a piece of cardboard with a mirror-shaped hole in it. When you remove the cardboard, you have a mirror-shaped area of paint.
I'm sure you have the all necessary skills to make up this!!!
Your answer
Follow this Question
Related Questions
Aiming, Camera Orbit 0 Answers
Camera Follow Positive Y only - C# 1 Answer
How do I rotate a bone with a camera object? 0 Answers
How to make the camera follow the character like in e.g. tomb Raider ? 1 Answer
Camera not facing back of character 0 Answers