Rendering and Texturing Cubes

function Start () {
var cube : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
renderer.material.mainTexture = Resources.Load(“grass.jpg”);
}

This is my code at the moment. I dragged grass.jpg from my desktop onto the “assets” area. This section of code is put onto a “Capsule”. There is no debug errors. I have found multiple questions with similar answers to this and got no use out of them. Is there something wrong with my code, or is there not enough code to do this?

Or, quite simply, is the Texture in the wrong place?

Thanks,

Zed.

Yes, read the docs for Resources.Load, particularly the part about omitting extensions. (Since there is no actual .jpg file that you will use. Speaking of which, don’t use .jpg in the first place, since it’s lossy compression.) Typically you would not use Resources.Load for this anyway, but instead make a public variable.

Also, you are assigning the texture to the object that the script is attached to, rather than using your cube variable.

var cubeTex : Texture;
...
    cube.renderer.material.mainTexture = cubeTex;