i have some problem. i am use this code
GetComponent<Renderer>().material.color = new Color(255,0,255,255);
Working but not what i want. look that.
Create new material but old one is still there. and gameobject using the old.
and then I used the following code
GetComponent<Renderer>().material.color.r = 50;
I got this error.
Assets/Script/Son.cs(32,53): error CS1612: Cannot modify a value type return value of `UnityEngine.Material.color'. Consider storing the value in a temporary variable
I do not know what to do.
Sorry for english :(.
Answer by The-Evster
Feb 13 at 08:04 PM
Try using this
GetComponent<Renderer>().material.color = new Color(50, GetComponent<Renderer>().material.color.g, GetComponent<Renderer>().material.color.b, GetComponent<Renderer>().material.color.a);
up vote if this helped
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
104 People are following this question.
Storing Renderer in a variable not working!
Assigning a sharedMaterial to multiple renderers that change together
How to make 2D physics objects graphics?
There is no Renderer attached to the MainCharacter game object
why do animated objects not behave like normal GameObjects?