- Home /
How would I show the value of a random value?
I'm stuck on how I would display (make a text object and give it the value of) the random.range number in my IEnumerator? Here's my code: https://pastebin.com/GhPkXgCr
For example, I want, if I pull a "Bell", an indicator of the number of points I got for it, to pop up (5-10(10 exclusive)). How would I go about doing this for all of the items?
Thanks.
Answer by viknesh2020 · Sep 30, 2018 at 07:29 AM
You have to convert your float/int value to a string and then assign the string to a text variable. I will give you an example here. You can work around on your script with the help of this example, I believe.
public Text displayRandomRange; //Make sure to add a Text UI component in your scene.
private string convertedRandyFloat;
void somefunction(){
float randy = Random.Range(2.5f, 31.5f);
convertedRandyFloat = randy.ToString();
displayRandomRange.text = convertedRandyFloat;
}
If you want to display the random value in each loop, create separate local variables of string.
Hope this helps !
Your answer
Follow this Question
Related Questions
How can I change textmesh to a random text snippet? 1 Answer
Random value for if statement 2 Answers
Assign a random value to var personality" upon asset creation (Java) 1 Answer
Calling 2 specific random float numbers in random.range using array not working! 2 Answers
How to make enemy prefab spawn at random times between 1.0f to 10.0f. 1 Answer