Created
September 11, 2017 21:12
-
-
Save 8ctopotamus/f9015d6830f8c2d08ab989259160760f to your computer and use it in GitHub Desktop.
Cycling through Cameras Unity3D
This file contains 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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class GameController : MonoBehaviour { | |
public GameObject[] gameCameras; | |
private int gameCameraIndex = 0; | |
void Start () { | |
FocusOnCamera (gameCameraIndex); | |
} | |
void Update () { | |
if (Input.GetMouseButtonDown (0)) { | |
ChangeCamera (1); | |
} | |
if (Input.GetMouseButtonDown (1)) { | |
ChangeCamera (-1); | |
} | |
} | |
void FocusOnCamera (int index) { | |
for (int i = 0; i < gameCameras.Length; i++) { | |
gameCameras [i].SetActive (i == index); | |
} | |
} | |
void ChangeCamera (int direction) { | |
gameCameraIndex += direction; | |
if (gameCameraIndex >= gameCameras.Length) { | |
gameCameraIndex = 0; | |
} | |
if (gameCameraIndex < 0) { | |
gameCameraIndex = gameCameras.Length - 1; | |
} | |
FocusOnCamera (gameCameraIndex); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment