How do i change color text depends on user input value. | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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

2nd Oct 2020, 11:57 PM
Sajjattul Islam Tamim
Sajjattul Islam Tamim - avatar
4 Respostas
+ 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
12th Oct 2020, 9:47 AM
Nadav Krashin
Nadav Krashin - avatar
+ 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
14th Oct 2020, 7:33 PM
Nadav Krashin
Nadav Krashin - avatar
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.
14th Oct 2020, 5:19 PM
Sajjattul Islam Tamim
Sajjattul Islam Tamim - avatar
0
and sorry about messy indentation its hard to write it with my phone
14th Oct 2020, 7:34 PM
Nadav Krashin
Nadav Krashin - avatar