How To Change A Ui Text Prefab Color?

I’m trying to instantiate a ui text prefab then changing it’s color like so:

uiElement = (GameObject)Instantiate(TextElementPrefab);
TextPrefabController textController = uiElement.GetComponent<TextPrefabController>();
textController.ChangeColor(new Color(244,122,66));

the “TextPrefabController” class is the class attached to the prefab. and contains the following method to change the text color.

public void ChangeColor(Color value)
{ 
gameObject.GetComponent<Text>().color = value;
}

The thing is the color is a bit orange but the prefab color appears white!! any idea why?
The following screenshot is taken from the unity editor at runtime, notice the color is orange and the text is still white!!

I found what’s wrong, I needed to change the color from 0-255 to 0-1
thanks to this post
https://answers.unity.com/questions/16583/recalculate-color-from-0255-to-01.html

I’m guessing the Text you’re looking at in the scene and the one you’re clicking on that is orange are not the same object. Does anything change when you press play and then stop? Sometimes the UI elements need this to redraw, but not commonly anymore.

Thanks for your reply Kurt, but i figured out what was wrong… i needed to assign a Color32 (which is 0-255 ) to the color and not just a Color (0-1)

1 Like