There are a few objects in the scene as well as a title. I want the title to change its text and color based on the object that is mouse-overed. The script below is added to each object that is intended to change the color and text of the title.

The title changes it's color correctly when values like Color.red are assigned but doesn't change color when values like new Color(254f, 152f, 203f).

public Text title;

void OnMouseEnter()
        title.color = Color.yellow;  // works well

        title.color = new Color(254f, 152f, 203f);  // doesn't work

    title.text = name;

void OnMouseExit()
    title.text = "DEFAULT VALUE";
    title.color = Color.white;

Is there a specific reason to the former method to work and latter not to work? How can I change the color of the Text element with custom values?


3 Answers 3


Constructor of Color class takes float parameters from 0 to 1 like this title.color = new Color(1f, 0.5f, 0.8f);

  • 1
    \$\begingroup\$ oh god... I don't know the reason behind me assuming the constructor took float values ranged from 0 to 255. It doesn't even make sense! I think I am too tired at this moment:) \$\endgroup\$
    – Varaquilex
    Commented Jan 13, 2015 at 8:35
  • \$\begingroup\$ This is the same answer all around. The thing is my "Title" is a GameObject>Canvas>UIText. The GameObjects has Text embeded into it. It seemed the only way to get my text to be able to set dynamically onto a grid. Or should I not do this? All the youtube tutorials put Text into a GameObject. So when I try to change it, it breaks runtime. \$\endgroup\$
    – ejbytes
    Commented Nov 18, 2020 at 22:38

You can do this with the code below:

title.color = new Color(254.0f/255.0f, 152.0f/255.0f, 203.0f/255.0f);
  • 3
    \$\begingroup\$ This should be accepted as correct answer. \$\endgroup\$
    – Eadel
    Commented Sep 6, 2017 at 19:13

If you'd like to pass RGBA in the common way you can also use Color32 that takes 4 bytes ranged from 0 - 255:

title.color = new Color32(254, 152, 203, 255);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .