public static Range ( float min, float max ) : float | ||
min | float | |
max | float | |
return | float |
int randomNumber = UnityEngine.Random.Range(1, 11); Debug.Log(randomNumber);
Color[] colors = { Color.red, Color.blue, Color.green, Color.yellow }; Color randomColor = colors[UnityEngine.Random.Range(0, colors.Length)]; Debug.Log(randomColor);
Transform[] spawnPoints = { spawnPoint1, spawnPoint2, spawnPoint3 }; Transform randomSpawnPoint = spawnPoints[UnityEngine.Random.Range(0, spawnPoints.Length)]; Instantiate(objectPrefab, randomSpawnPoint.position, randomSpawnPoint.rotation);The UnityEngine.Random.Range function is a part of the UnityEngine package library.