Question

I have been trying to make the apple textured by putting in these codes:

GameObject cube = Instantiate(Resources.Load("apple", typeof(GameObject))) as GameObject;
Texture my3dModelTexture = Resources.Load("Textures/apple2", typeof(Texture)) as Texture;
cube.renderer.material.mainTexture = my3dModelTexture;

However, my apple appeared to be untextured. But then I tried the same concept on a cube, and it is working.

GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

Could someone please help? I have been trying a lot of methods, but none of them seem to work and I still cant find the reason why.

No correct solution

OTHER TIPS

//assuming there is image file apple.png or jpg in the resource folder

Texture2D tex = Resources.Load(apple) as Texture2D;
if(tex == null)
    Debug.LogError("Error loading image");
else
    Debug.Log ("Scuccess in loading image");
cube.renderer.material.mainTexture = tex;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top