- Home /
The question is answered, right answer was accepted
How to enter minimum and maximum values for random.Range in the inspector?
Hey, I have an AttackDamage script that makes use of Random.Range to create a damage ceiling for characters attacks. The problem is I can't get it to display anything but 1 number in the inspector, so I have to declare the damage in the script itself rather than on each character using the AttackDamage script. How can I achieve this?
Answer by tormentoarmagedoom · Sep 15, 2018 at 06:04 PM
Good day.
RandomRange using int or float? Lets say int.
You only need to create 2 public integrer variables and use them in the random function.
public int maxRandom, minRandom;
Then save the script and, in the inspector you can assign values to both variables.
In your code you only need to use them
[...]
Code.....Random.Range(minRandom, maxRandom)....Code
[...]
Thats all! Bye!
Integer Random.Range() is exclusive (it can't result in the maximum value), so if you want to be able to define the $$anonymous$$imum damage as, say, 1, and the maximum as 10, the function would look more like:
Random.Range($$anonymous$$Random, maxRandom + 1)