📅  最后修改于: 2023-12-03 14:46:55.156000             🧑  作者: Mango
Random.Range is a method in Unity that generates a random number within a specific range of values. This method can be useful in a variety of situations, such as creating randomized game elements or generating random test data. Let's take a closer look at how to use Random.Range in Unity C#.
public static float Range(float minInclusive, float maxExclusive);
public static int Range(int minInclusive, int maxExclusive);
Here are a few examples of how to use Random.Range in Unity C#:
// Generates a random number between -1.0f and 1.0f.
float randomFloat = Random.Range(-1.0f, 1.0f);
// Generates a random number between 0 and 10, inclusive.
int randomInt = Random.Range(0, 11);
// Generates a random number between -100 and 100, inclusive.
int randomInt2 = Random.Range(-100, 101);
Overall, Random.Range is a useful tool to have when working with Unity C#. With a few simple parameters, you can generate a random number within a specified range quickly and easily.