How do you change a color in SpriteRenderer?

How do you change a color in Spriterenderer with script? Thanks in advance.

renderer.material.SetColor(“_Color”, Color.red);

1 Like

Or rather, you can probably just use SpriteRenderer.color

SpriteRenderer renderer = //Get the renderer via GetComponent or have it cached previously
renderer.color = new Color(0f, 0f, 0f, 1f); // Set to opaque black
6 Likes

Thanks! I added this line renderer = gameObject.GetComponent(SpriteRenderer); into the Start function and now it works fine! You saved me some headache, XGundam05.

jquave: Thanks to you, as well.

This will apply a Material Shader Tint colour to your sprite, this doesn’t alter the SpriteRenderer colour. Still handy to know though! :slight_smile:

1 Like

How do I change the SpriteRenderer color then?

https://discussions.unity.com/t/520132/3