Skip to content

Instantly share code, notes, and snippets.

@nathanpc
Created June 7, 2022 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanpc/90b6237136aeb230ddcfe2f09fee9630 to your computer and use it in GitHub Desktop.
Save nathanpc/90b6237136aeb230ddcfe2f09fee9630 to your computer and use it in GitHub Desktop.
Switch Unity Render Camera for Video Mapping
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