Last active
August 30, 2015 14:49
-
-
Save adarapata/94d06e4b426ded85c0e6 to your computer and use it in GitHub Desktop.
複数カメラ切り替えマン
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| public class MultiCamera : MonoBehaviour | |
| { | |
| public Camera[] cameras; | |
| public KeyCode switchKey; | |
| private int current = 0; | |
| public bool isAutoFind; | |
| void Start() | |
| { | |
| if(isAutoFind) cameras = FindObjectsOfType<Camera>(); | |
| Activate(); | |
| } | |
| void Update () | |
| { | |
| if(Input.GetKeyDown(switchKey)){ | |
| current = (current >= cameras.Length - 1) ? 0 : current + 1; | |
| Activate(); | |
| } | |
| } | |
| private void Activate() | |
| { | |
| for(int i = 0;i < cameras.Length; i++) | |
| { | |
| bool isActive = (i == current); | |
| cameras[i].gameObject.SetActive(isActive); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment