Using Screenshot as Texture

I want to take a screenshot and use it as a material texture for another object.

Script so far:

public IEnumerator TakeSnapshot(int width, int height)
{
    yield return new WaitForSeconds(5);

    Texture2D texture = new Texture2D (width, height, TextureFormat.RGB24, true);

    texture.ReadPixels(new Rect(0, 0, width, height), 0, 0);

snapshot = texture;
}

then im using

fotoPlane.renderer.material.mainTexture = snapshot;

but this is just creating a gray texture instead of getting the screen image.

i forgot the texture.Apply(); after texture.ReadPixels.
That solved it. I will leave the question here in case someone has the same problem.


    StartCoroutine(TakeSnapshot(Screen.width,Screen.height));

public IEnumerator TakeSnapshot(int width, int height)
{
    yield return new WaitForSeconds(0.1F);
    Texture2D texture = new Texture2D (width, height, TextureFormat.RGB24, true);
    texture.ReadPixels(new Rect(0, 0, width, height), 0, 0);
    texture.Apply();
    snapshot = texture;
}

and then


    gameObject.renderer.material.mainTexture = snapshot;

Nice. It looks like using “yield return new WaitForEndOfFrame();” might be a little cleaner.

Very useful information! Thanks a lot!=)

Thank you it’s very useful for me.
I was wondering if it’s possible to snapshot a specific region of the screen?
I try to make a little drawing game and I want to save only the region of the paper.
Any idea how can I do that?
Thank you

95107-dessin.jpg