Dynamicaly Creating A Plane With A JPG Material ...

Hi,

I want to load Image to a plane at runtime…

I have seen this wiki (unifycommunity.com)
But I want a more simple basic loading code

I am dreaming something like this…

GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
plane.name = "myPlane";
plane.transform.position = new Vector3(0, 0, 0);
plane.transform.Rotate(90f, 0f, 0f);
//the lines above creates the plane and loads it...
    
//1 is a jpg in resources folder
//But this line just gives me a pink plane not my jpg...
plane.renderer.material = Resources.Load("1", typeof(Material)) as Material;

How can I achieve this?
thanks

Almost. You want:

plane.renderer.material.mainTexture = Resources.Load("1", typeof(Texture)) as Texture;

Try this instead… ( as of 2018 )

plane.GetComponent().material.mainTexture = Resources.Load(“1”, typeof(Texture)) as Texture;

mickbanks.com