SwitchCamera

From Unify Community Wiki
Revision as of 02:50, 28 July 2010 by OldMonk (Talk | contribs)

Jump to: navigation, search

Author: JakeH

Contents

Description

This script lets you switch between cameras in your scene.

Usage

Attach the script any GameObject and define the variables.

JavaScript- SwitchCamera.js

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

function Start () {

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

}

function Update () {

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

} </javascript>

CSharp- SwitchCamera.cs

<csharp> using UnityEngine; using System.Collections;

public class SwitchCamera : MonoBehaviour {

public GameObject camera1; public GameObject camera2;

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

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

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox