Created
June 7, 2022 00:15
-
-
Save nathanpc/90b6237136aeb230ddcfe2f09fee9630 to your computer and use it in GitHub Desktop.
Switch Unity Render Camera for Video Mapping
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; | |
/// <summary> | |
/// Switches the camera automatically depending on the scene required. | |
/// </summary> | |
public class RenderCameraSwitcher : MonoBehaviour { | |
public RenderTexture renderTexture; | |
protected Camera lastCamera; | |
/// <summary> | |
/// Switches the camera that is currently being rendered by the render texture. | |
/// </summary> | |
/// <param name="camera">New camera that will be rendered.</param> | |
public void SwitchCamera(Camera camera) { | |
// Stops rendering the last selected camera. | |
if (lastCamera != null) | |
lastCamera.targetTexture = null; | |
// Change the currently rendered camera. | |
camera.targetTexture = renderTexture; | |
lastCamera = camera; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment