---
title: "Unity3D相机切换2"
author: "chinaloft"
date: "2012-12-10T23:39:21Z"
tags: []
categories: ["移动开发"]
slug: "unity3d-2"
draft: false
lastmod: "2012-12-30T16:06:43Z"
id: 1745531
url: "https://bvu.iteye.com/blog/1745531"
---

Unity3D相机切换

var camera0 : Camera;
var camera1 : Camera;
function Update () {
if (Input.GetKey ("1"))
    {
        camera1.enabled = true;
        camera0.enabled = false;
    }
    if (Input.GetKey ("2"))
    {
        camera1.enabled = false;
        camera0.enabled = true;
    }

}

function OnGUI () {

GUI.Box (Rect (10,10,100,90), "Camera Switch");

        // Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
        if (GUI.Button (Rect (20,40,80,20), "Camera 1")) {
                camera1.enabled = true;
        camera0.enabled = false;
        }

        // Make the second button.
        if (GUI.Button (Rect (20,70,80,20), "Camera 2")) {
                camera1.enabled = false;
        camera0.enabled = true;
        }
}

![](http://dl.iteye.com/upload/attachment/0078/6304/a24f4d39-1526-37db-8200-98c73340e1ef.jpg)