MultipleCameraSwitcher

From Unify Community Wiki
Revision as of 06:40, 17 October 2010 by StephenL (Talk | contribs)

Jump to: navigation, search


Author: StephenL

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.

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.

JavaScript - MultipleCameraSwitcher.js

<javascript>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