SwitchCamera

From Unify Community Wiki
Revision as of 10:21, 28 July 2010 by NCarter (Talk | contribs)

Jump to: navigation, search

Author: JakeH

Contents

Description

This script lets you switch between two cameras in your scene.

Usage

Attach the script to amy GameObject and define the variables.

JavaScript- SwitchCamera.js

<javascript> var camera1 : Camera; var camera2 : Camera;

function Start () {

  camera1.enabled = true; 
  camera2.enabled = false; 

}

function Update () {

  if (Input.GetKeyDown ("2")){ 
     camera1.enabled = false; 
     camera2.enabled = true; 
  } 
  if (Input.GetKeyDown ("1")){ 
     camera1.enabled = true; 
     camera2.enabled = false; 
  }     

} </javascript>

CSharp- SwitchCamera.cs

<csharp> using UnityEngine; using System.Collections;

public class SwitchCamera : MonoBehaviour {

public Camera camera1; public Camera camera2;

// Use this for initialization void Start () { camera1.enabled = true; camera2.enabled = false; }

// Update is called once per frame void Update () { if (Input.GetKeyDown("2")) { camera1.enabled = false; camera2.enabled = true; } if (Input.GetKeyDown("1")) { camera1.enabled = true; camera2.enabled = false; } } } </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox