-2
\$\begingroup\$

So I am trying to change my color of my sprite to a rgb color. Now I can just change it to a color like red, black or blue...

 m_spriteRenderer.color = Color.blue;

Thanks,

\$\endgroup\$
1
\$\begingroup\$

You can pass the color you want to the constructor of the Color object.

Here is a copy of the documentation's example:

using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        Color newColor = new Color(0.3f, 0.4f, 0.6f);
    }
}

You can also use it like that:

Color newColor = new Color(0.3f, 0.4f, 0.6f);
m_spriteRenderer.color = newColor;

You can see an example of how it can be used in the documentation of the SpriteRenderer.color function.

\$\endgroup\$
  • 1
    \$\begingroup\$ If you find it easier to think of colours in byte values, you can use new Color32(127, 63, 0xFF). These 32-bit colours will implicitly convert to and from the floating point color type, so you can use whichever is clearest for your needs. \$\endgroup\$ – DMGregory Oct 9 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy