I want to change the texture of my GameObject at runtime. For that I use Resources.Load, to load the new texture file. If I press “1” he should change the texture but only removes the current (so that the object is white) but doesn’t add the new one. My texture file is located in “Assets/Resources”. Do I miss something?
if(Input.getKey("1")) {
Texture foo = Resources.Load("my_texture.jpg") as Texture; // also tried Texture2D
target.renderer.material.mainTexture = foo; // target is my gameobject
}
I found the error I loaded the resource with the image type. For example: “my_texture.jpg” but you have to load it without the type, like: “my_texture”.
Texture foo = Resources.Load("my_texture") as Texture; // without image type