I need a Simple and Clear example for how to add a texture (image) to a quad in C#

Every answer to this question that I have found is different. Seems like it should have a straightforward answer. In simple terms… My question is:

I have created a quad entirely in a C# script. I have a .png file in my Resources folder, and I need the code to load it as a texture and show up on the quad. That’s it!

What’s the simplest way to do this? (with a code example) (no deprecated functions please :slight_smile:

Thanks!
-j

In Monobehaviour attached to quad

  1. Load texture

    Texture texture = Resources.Load(“TextureName”) as Texture;

  2. Now wherever you want to add texture to quad write this

    GetComponent().material.mainTexture = texture;

OK folks, I came up with my answer by poking around the interwebs (the answers given were too sparse).

I HOPE THIS IS USEFUL for other people with the same question that I had:

  1. I created a Resources folder inside of the Assets folder.

  2. I Created a Material in the Resources folder which I renamed to “Whatever”.

  3. I dragged a .png file called “my_image” into the Resources folder.

  4. I added the following code to the Start method:

    GameObject quad = GameObject.CreatePrimitive( PrimitiveType.Quad );

    Material quadMaterial = (Material)Resources.Load( “Whatever” );

    quad.GetComponent().material = quadMaterial;

    Texture2D myTexture = Resources.Load( “my_image” ) as Texture2D;

    quad.GetComponent().material.mainTexture = myTexture;