Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

how to change the color of an object in unity c#

//You can either change material color of an object, or a color of component SpriteRenderer,
//which doesn't really matter unless you have lights added in yout project.

//so lets get a color (blue for this example)
public Color myColor = new Color(0, 0, 1, 1); //(r,g,b,a) 
//changing material color looks like this : 
gameObject.GetComponent<Renderer>().material.color = myColor;

//changing SpriteRenderer color looks like this :
gameObject.GetComponent<SpriteRenderer>().color = myColor;
 
PREVIOUS NEXT
Tagged: #change #color #object #unity
ADD COMMENT
Topic
Name
7+8 =