Managing multiple cameras in unity is a very painful thing, "camera Preview" is not very practical, the window is too small, the scale can not be adjusted.
Disabled in numerous cameras, enable to view camera position setting perspective, very cumbersome.
The purpose of the Security camera is to simplify the process. Just put the script in the project directory and drag it to each camera in the scene,
including Maincamera. Now you can quickly switch between viewing the actual effects of each camera, and in Unity's hierarchy view (Hierarchy), click on the camera you want to set,
You can see the effect of this camera in the game view, no need to turn off the other camera.
Note that to use the security camera script, you should give each camera a unique name and make sure that there is a main camera and the tag tag is "Maincamera",
If you forget to do so. The system will alert you. In addition, the script provides a static method called "Changecamera",
This method only needs a string, you can use the script to quickly switch the camera.
Like this:
using unityengine;
using system.collections; Public class cameraswap : monobehaviour { void update () { //pressing 0, 1, 2, and 3 will swap before the cameras named "main Camera ", //" camera 1 ", " camera 2 ", and "Camera 3" which have security camera added: if (Input.getkeydown (KEYCODE.ALPHA0)) {
securitycamera.changecamera ("Main camera"); if ( Input.getkeydown (KEYCODE.ALPHA1)) {  
Securitycamera.changecamera ("camera 1"); }//unity3d Tutorial Manual: Www.unitymanual.com if (Input.getkeydown (KEYCODE.ALPHA2)) {
securitycamera.changecamera ("camera 2"); if ( Input.getkeydown (KEYCODE.ALPHA3)) {
securitycamera.changecamera ("camera 3"); } }}
Ok. Let's test it.
Other ways to manage cameras
Description: This chapter, let's learn how to switch multiple cameras in the same scene.
First, let's set up the scene, 2 cube,3 camera,1 a parallel light. As follows
Adjust the position of the three cameras, for example, from the perspective below
Side view
Front view
Top view
Then we create an empty object Gameobject---Create empty named Camearcontroller, which is used to control the logic.
Then we create a JS script in the Project panel.
Write the following code var Camera1:gameobject;
var camera2:gameobject;
var camera3:gameobject;
function Update ()
{
if (Input.getkeyup (KEYCODE.ALPHA1))
{
Onactivefalse ();
Camera1.active=true;
}else if (Input.getkeyup (KEYCODE.ALPHA2))
{
Onactivefalse ();
Camera2.active=true;
}else if (Input.getkeyup (KEYCODE.ALPHA3))
{
Onactivefalse ();
Camera3.active=true;
}
}
function Onactivefalse ()
{
Camera1.active=false;
Camera2.active=false;
Camera3.active=false;
The content of the copy code is that when the program is running, pressing the number keys in a few digits toggles the camera in the scene.
The main content is the camera. The settings for the active property.
After writing the code, we drag the JS code onto the Camearcontroller object in the hierarchy panel. Make sure this object is selected, and in inspector, we can see the variables declared in the code CAMERA1,CAMERA2,CAMERA3
2011-9-26 13:35:02 upload Download attachment (18.04 KB)
Drag the camera in the hierarchy panel into the position of none (Game Object).
Save, run, press the number key, the camera can be switched.