Random.Range 范围
static function Range (min : float, max : float) : float
Description描述
Returns a random float number between and min [inclusive] and max [inclusive] (Read Only).
返回一个随机浮点数,在min(包含)和max(排除)之间。(只读)
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public GameObject prefab;
void Start() {
Vector3 position = new Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10));
Instantiate(prefab, position, Quaternion.identity);
}
}
// Instantiates prefab somewhere between -10 and 10 on the x-z plane
//在x-z平面实例化预设,-10~10之间
var prefab : GameObject;
function Start () {
var position = Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10));
Instantiate(prefab, position, Quaternion.identity);
}
• static function Range (min : int, max : int) : int
Description描述
Returns a random integer number between min [inclusive] and max [exclusive] (Read Only).
返回一个随机整数,在min(包含)和max(排除)之间。(只读)
If max equals min, min will be returned. The returned value will never be max unless min equals max.
如果max等于min,将返回min。返回值永远不会是max,除非min等于max。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public void Awake() {
Application.LoadLevel(Random.Range(0, Application.levelCount));
}
}
// Loads a random level from the level list
//将从关卡列表,加载一个随机关卡
Application.LoadLevel(Random.Range(0, Application.levelCount));
最后修改:2011年8月17日 Wednesday 19:02