Switching plane texture through script
Complete newbie here. I have two planes, with albedo set to green and white. I have a texture (png, 16-bit, 256x256, it just has an alphabet with transparent pixels all around) that I'd like the plane to show at runtime, when an event happens. After searching the internet including this forum, I did this:
Material newMaterial = (Material) Resources.Load("AnotherMaterial", typeof(Material)); planeObject.GetComponent < MeshRenderer > ().material = newMaterial;
I can see that when the event triggers, the color of the plane changes to a pinkish color, but not to the texture. Same thing happens on either plane. I also tried not using my png texture, but making "AnotherMaterial" have a different color. Result is the same.
Could someone explain how to do this right?
Answer by karthikveeramani · Jan 22, 2017 at 05:46 AM
OK I figured out the answer shortly after my post. Leaving it here in case someone else has the same trouble.
It looks like Resources.Load() works only if the asset is under a folder called Resources (under Assets directory). So I made Resources/Materials folder, and changed my load to
Material newMaterial = (Material) Resources.Load("Materials/AnotherMaterial", typeof(Material));
and that worked. I didn't realize that the "pink color" that showed up earlier was due to the material not being found - I had assumed I'd see an error in that case.
Your answer
![](https://koobas.hobune.stream/wayback/20220612105326im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Are there no other way to paint Unity terrain than with textures? 1 Answer
TextureType grayscale 0 Answers
change color of part of plane 1 Answer
Help with terrain texture and grass blending 1 Answer
Unity2D: Remove Shader Colour 0 Answers