- Home /
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;
         }
     }
 }
Answer by Xyrious Industries · May 18, 2015 at 06:14 AM
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.
Answer by sas_88 · May 18, 2015 at 09:16 AM
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;
      }
  }
I'm trying to get the texture in game, could I do that and then replace texture with the picture I take in game, so that the texture changes each time I run the function I described above? Also, is it possible to change a material so it updates every instance of it while the game plays?
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                