Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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