I'm trying to get a picture in game and display it on a plane

I’m using the following very simple code. I got almost all of this from previous answers and, as a result, don’t really understand the limitations of it. So I just want to know it this can work and if so how I can do it. This code is on the plane I want to to display the material on, it has one blank material, a box collider, and a network view.

using UnityEngine;
using System.Collections;

public class MaterialChanger : MonoBehaviour {
	Texture2D texture;
	bool getPic = true;
	void OnPostRender () {
		if (getPic) {
			texture = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, false);
			texture.ReadPixels (new Rect (0, 0, Screen.width, Screen.height), 0, 0, false);
			texture.Apply ();
			GetComponent<Renderer> ().material.mainTexture = texture;
			getPic = false;
		}
	}
}

Likely, if you want to put a picture on a plane, you must make the picture a material, then you can drag and drop the material unto the plane.

Hi,

Declare Texture2D as public and assign the texture.

 using UnityEngine;
 using System.Collections;
 
 public class MaterialChanger : MonoBehaviour
 {
     Public Texture2D texture;

     void Start()
     {
      GetComponent<Renderer> ().material.mainTexture = texture;
     }
 }