- Home /
Question by
eam123 · Mar 08, 2019 at 05:37 PM ·
camerascreenshot
Camera ScreenShot
I have two cameras on the scene. One attached to the actor (CamA) and other is a scene view (CamB).
I want to take a screenshot of the CamA but the code below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraGrab : MonoBehaviour
{
Camera[] myCams;
// Start is called before the first frame update
void Start()
{
myCams = Camera.allCameras;
}
// Update is called once per frame
void Update()
{
Camera camera = myCams[0];
RenderTexture currentRT = RenderTexture.active;
RenderTexture.active = camera.targetTexture;
camera.Render();
Texture2D image = new Texture2D(camera.targetTexture.width, camera.targetTexture.height);
RenderTexture.active = currentRT;
}
}
Is returning:
NullReferenceException: Object reference not set to an instance of an object CameraGrab.Update () (at Assets/CameraGrab.cs:24)
Any suggestion for this problem? There is a way to resize the image?
If I change the camera show in the display, can I keep grab the screenshots from a specific camera, among all available?
Comment
Your answer