Skip to content

Instantly share code, notes, and snippets.

@adarapata
Last active August 30, 2015 14:49
Show Gist options
  • Select an option

  • Save adarapata/94d06e4b426ded85c0e6 to your computer and use it in GitHub Desktop.

Select an option

Save adarapata/94d06e4b426ded85c0e6 to your computer and use it in GitHub Desktop.
複数カメラ切り替えマン
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