Advertisemen
Unity Turtorial: 25 Changing between cameras !
Unity3D TUTORIAL: 25 Changing between cameras !
THIS IS C# script: GOOD 4 2D GAMES AND 3D GAMES !
--------------------------------------------------------------------------------------
DIRECT DOWNLOAD HERE
---------------------------------------------------------------------------------
THIS IS BACKUP IN TEXT FORM TUTORIAL 25
1. Create New C# and name it :
CameraController
2. Copy & Past this text and save C# :
---------------------------------------------------------------------------------
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public Camera[] cameras;
private int currentCameraIndex;
// Use this for initialization
void Start () {
currentCameraIndex = 0;
//Turn all cameras off, except the first default one
for (int i=1; i<cameras.Length; i++)
{
cameras[i].gameObject.SetActive(false);
}
//If any cameras were added to the controller, enable the first one
if (cameras.Length>0)
{
cameras [0].gameObject.SetActive (true);
Debug.Log ("Camera with name: " + cameras [0].camera.name + ", is now enabled");
}
}
// Update is called once per frame
void Update () {
//If the c button is pressed, switch to the next camera
//Set the camera at the current index to inactive, and set the next one in the array to active
//When we reach the end of the camera array, move back to the beginning or the array.
if (Input.GetKeyDown(KeyCode.C))
{
currentCameraIndex ++;
Debug.Log ("C button has been pressed. Switching to the next camera");
if (currentCameraIndex < cameras.Length)
{
cameras[currentCameraIndex-1].gameObject.SetActive(false);
cameras[currentCameraIndex].gameObject.SetActive(true);
Debug.Log ("Camera with name: " + cameras [currentCameraIndex].camera.name + ", is now enabled");
}
else
{
cameras[currentCameraIndex-1].gameObject.SetActive(false);
currentCameraIndex = 0;
cameras[currentCameraIndex].gameObject.SetActive(true);
Debug.Log ("Camera with name: " + cameras [currentCameraIndex].camera.name + ", is now enabled");
}
}
}
}
---------------------------------------------------------------------------------
Advertisemen
Tidak ada komentar:
Posting Komentar