Here's my issue : I created a material composed of a normal map and an image (base RGB), I would like to change the base (RGB) via scripting. My aim is to be able to choose between several textures and apply different colors to a gameobject.
If anyone could help that would be a lot of help :D, thanks !
transform.renderer.material.color = Color.blue;
//if you have muliple color atributes in the shader you call them specifically
Thanks a lot mate ! Could I do the same for a picture instead of a color ? :D
Answer by Namey5
public Texture2D tex;
GetComponent<Renderer>().material.SetTexture ("_MainTex", tex);
"_MainTex" might be different depending on what they have named the property in the shader, although that is the common naming method for the primary albedo.
Thanks a lot mate ! :D
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
8 People are following this question.
Light based texture change on material
Texture2D to Texture3D
How to change a value in custom shader through script, C#
How do you make an X-ray vision following the mouse?
Shader Shadow Effect Issues