using Random = UnityEngine.Random;
public float minFloat;
public float maxFloat;
public int minInt;
public int maxInt;
private void GenerateRandom()
{
float ranFloat = Random.Range(minFloat, maxFloat); // 浮点型可返回maxFloat
int ranInt = Random.Range(minInt, maxInt); // 整型不可返回maxInt
}
注意:浮点型与整型随机数的区别。
// 四舍五入有两种方法
Mathf.RoundToInt(ranFloat); // 1.
Mathf.FloorToInt(ranFloat + 0.5f); // 2.