- Home /
Dynamicaly Creating A Plane With A JPG Material ...
Hi,
I want to load Image to a plane at runtime...
I have seen this wiki (http://www.unifycommunity.com/wiki/index.php?title=CreatePlane) 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
Comment
Best Answer
Answer by Waz · Sep 02, 2011 at 06:46 AM
Almost. You want:
plane.renderer.material.mainTexture = Resources.Load("1", typeof(Texture)) as Texture;
Answer by Banksy · Jun 24, 2018 at 12:14 AM
Try this instead... ( as of 2018 )
plane.GetComponent().material.mainTexture = Resources.Load("1", typeof(Texture)) as Texture;