0
How do i change color text depends on user input value.
Hey, I'm developing an app project with unity and c#, at this point, i want change the text color, depends on user input an intiger value. As example : On temperature measument, when user input a value of temperature of 70, on the user interface screen thattext of (70) would show with a orange color to make it a warning condition.. I'm using textmashpro text field on unity. Please help me to get fix that criteria. Thank you
4 Answers
+ 2
Here are the steps I would do to deal with your problem:
1. Create a C# script and attach it to your tmpro Game Object
2.Open your script
3.Make sure you use âTMProâ name space
4.Create a global var to store the text mesh pro component
5. In the start method use GetComponent<TextMeshProUGUI> to attach the component to the variable you created in the last step.
6. On your update method make sure to set the text by writing - âtmpro var nameâ.text = player input.toString()(if it is a number)
7. After changing the text to fit the player input make an if else statement to check how big the number is and change the color accordingly with - âtmpro var nameâ.color = Color.(whatever color you want)
If this wasenât clear enough I can try to explain again in more detail
+ 2
Tried to make it as clear as possible.
I donât know how you get your user input so you will have to connect that to this script on your program by yourself.
(The code wonât run here becuase this does not support unity syntax obviously)
https://code.sololearn.com/cbqmQf4d2E5j/?ref=app
0
Thank you Nadav, for reply i understan the function behind it, it would be great if get an sample code example. As how the if statement will work to change the color.
0
and sorry about messy indentation its hard to write it with my phone