Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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()
{
    switch(name)
    {
    CONDITION1:
        title.color = Color.yellow;  // works well
        break;

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

    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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
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:) –  Varaquilex Jan 13 at 8:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.