Created
October 18, 2017 05:39
-
-
Save igolden/9565e53df1ac91c114f67a6e2b5ecce3 to your computer and use it in GitHub Desktop.
Main Camera toggle in Unity C# - toggles between two camera transforms
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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class CameraHandler : MonoBehaviour { | |
// Represents the main camera | |
GameObject mainCamera; | |
// Update is called once per frame | |
void Update () { | |
if (Input.GetKeyDown(KeyCode.Space)) | |
{ | |
// Target your main camera | |
mainCamera = GameObject.Find("Main Camera") as GameObject; | |
// Conditionally handle position changing | |
if (mainCamera.transform.position.z == 0) | |
{ | |
mainCamera.transform.position = new Vector3(0, 3, -2); | |
// optional rotation | |
// mainCamera.tranform.rotation.x = -15; | |
} else | |
{ | |
mainCamera.transform.position = new Vector3(0, 0, 0); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment