- Home /
Is it possible to give a color to int variables?
This looks like a dumb question, but I really need a solution.
How do you color an integer variable if its called in a text. consider the example below:
int mc;
private void Start()
{
mc = GameObject.FindGameObjectWithTag("MC").GetComponent<MissionCount>().missionCount;
missionBox.GetComponentInChildren<Text>().text = "Your mission is to break " + mc + " Squares";
}
missionCount is an integer value, and I want to change its color to something different. Please help me if you understood the question.
I didn't understand it very well, but do you want to choose these colors? example, if the variable missionCount is equal to 1 is the color red? I didn't understand yet
Not really.
I have missionCount int variable. and I want to add that into a text component of another GameObject. the code above is working fine and is giving me, what I want. But I want to change the color of 'mc' in the text. so the result will be:
missionBox.GetComponentInChildren<Text>().text = "Your mission is to break " + mc + " Squares";
but mc will be colored differently.
Answer by FeedMyKids1 · Jan 27, 2021 at 04:21 PM
Yes.
Try this https://answers.unity.com/questions/592242/changing-color-of-a-string-1.html
Rich Text https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/StyledText.html
We are <color=#ff0000ff> colorfully </color> amused ("colorfully" will be red.)
You can also use <color = > text </color>
with predefined colors.