I want to take screen shot within gameplay in mobile and then share it.
I have done this with CaptureScreenShot but it captures complete screen, i want only specific area i.e smaller panel only that comes after game to show score.
Plz help me out.
I want to take screen shot within gameplay in mobile and then share it.
I have done this with CaptureScreenShot but it captures complete screen, i want only specific area i.e smaller panel only that comes after game to show score.
Plz help me out.
To save a part of the screen in a Texture2D you can use the function Texture2D.ReadPixels after assigning to your camera a targetTexture and setting this targetTexture as active.
Here the code :
using UnityEngine;
using System.Collections;
using EasyEditor;
public class TakeScreenShot : MonoBehaviour {
public Material aMaterial;
public int height = 100;
public int width = 100;
[Inspector]
void TakeScreenshot()
{
Camera camera = GetComponent<Camera>();
RenderTexture cameraOutputTexture = new RenderTexture(camera.pixelWidth, camera.pixelHeight, 0);
camera.targetTexture = cameraOutputTexture;
RenderTexture currentActiveRT = RenderTexture.active;
RenderTexture.active = cameraOutputTexture;
camera.Render();
Texture2D texture2D = new Texture2D(width, height, TextureFormat.RGB24, false);
texture2D.ReadPixels(new Rect(0, 0, width, height), 0, 0);
texture2D.Apply();
RenderTexture.active = currentActiveRT;
aMaterial.mainTexture = texture2D;
camera.targetTexture = null;
}
}