MultipleCameraSwitcher

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Description)
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
 
Line 12: Line 12:
  
 
==JavaScript - MultipleCameraSwitcher.js==
 
==JavaScript - MultipleCameraSwitcher.js==
<javascript>var camera1 : Camera;  
+
<syntaxhighlight lang="javascript">var camera1 : Camera;  
 
var camera2 : Camera;  
 
var camera2 : Camera;  
 
var camera3 : Camera;
 
var camera3 : Camera;

Latest revision as of 20:48, 10 January 2012


Author: StephenL

[edit] Description

A script that allows you to switch between different cameras in your scene. Supports four camera views that can be toggled with a button. Requires Unity 2.6 or later.

[edit] Usage

Drag four cameras into the appropriate slots in the inspector after you've attached the script to an object. The script has a startCamera public variable; this is the camera that scene will start with. To switch between camera views, the default button is C.

[edit] JavaScript - MultipleCameraSwitcher.js

var camera1 : Camera; 
var camera2 : Camera; 
var camera3 : Camera;
var camera4 : Camera;
public var startCamera : int = 1;
 
function Start () 
{ 
   camera1.enabled = true; 
   camera2.enabled = false; 
   camera3.enabled = false;
   camera4.enabled = false;
   startCamera = 1;
} 
 
function Update () 
{ 
   if (Input.GetKeyDown ("c") && (startCamera == 1))
   { 
	  startCamera = 2;
      camera1.enabled = false; 
      camera2.enabled = true; 
	  camera3.enabled = false;
	  camera4.enabled = false;
   } 
 
   else if (Input.GetKeyDown ("c") && (startCamera == 2))
   { 
	  startCamera = 3;
      camera1.enabled = false; 
      camera2.enabled = false; 
	  camera3.enabled = true;
	  camera4.enabled = false;
   } 
 
   else if (Input.GetKeyDown ("c") && (startCamera == 3))
   { 
	  startCamera = 4;
      camera1.enabled = false; 
      camera2.enabled = false; 
	  camera3.enabled = false;
	  camera4.enabled = true;
   } 
 
   else if (Input.GetKeyDown ("c") && (startCamera == 4))
   { 
	  startCamera = 1;
      camera1.enabled = true; 
      camera2.enabled = false; 
	  camera3.enabled = false;
	  camera4.enabled = false;
   } 
 
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox