您的位置:首页 > 移动开发 > Unity3D

读《Unity3D游戏开发》笔记工具类

2016-04-01 15:38 363 查看
1、Time类

//Time工具类
void OnGUI()
{
GUILayout.Label("当前游戏时间: "+Time.time);
GUILayout.Label("上一帧消耗的时间:"+Time.deltaTime);
GUILayout.Label("固定增加的时间:" + Time.fixedTime);
GUILayout.Label("上一帧固定消耗的时间:" + Time.fixedDeltaTime);
}


其中除了Time.fixedDeltaTime之外,其他三个都是只读的。

time: 从游戏开始到现在所用的时间 readOnly

timeSinceLevelLoad:这是以秒计算到最后的关卡已经加载完的时间 readOnly

deltaTime:以秒计算,完成最后一帧的时间 readOnly

fixedTime:这是以秒计自游戏开始的时间 readOnly

fixedDeltaTime:以秒计间隔,在物理和其他固定帧速率进行更新

maximumDeltaTime:一帧能获得的最大时间,物理和其他固定帧率更新

smoothDeltaTime:一个平滑淡出 Time.deltaTime readOnly

timeScale:传递时间的缩放,这可以用于减慢运动效果

frameCount:已经传递的帧的总数 readOnly

realtimeSinceStartup:以秒计,自游戏开始的实时时间 readOnly

captureFramerate:时间会在每帧(1.0/captureFramerate)前进,不考虑真实时间

unscaledDeltaTime:以秒计算,完成最后一帧的时间(不计算Timescale) readOnly

unscaledTime:从游戏开始到现在所用的时间(不计算Timescale) readOnly

2、等待

void Start () {
StartCoroutine(waitTest());
}
//等待
IEnumerator waitTest()
{
print("1-----------" + Time.time);
yield return new WaitForSeconds(5);
print("2-----------"+Time.time);
}
这个涉及到协程,暂时知道写法,以后用到的时候需要细查一下资料

3、随机数

<span style="white-space:pre">	</span>//随机数
int temp_a = Random.Range(1, 10); //返回一个1-10之间的随机数
int temp_b = Random.Range(1, 2);
float temp_color = Random.value; //返回一个0.0到1.0之间的浮点数(两端都是闭区间)
Quaternion temp_qua = Random.rotationUniform;//返回一个随机旋转角度(平均分布)
Quaternion temp_qua1 = Random.rotation;//返回一个随机旋转角度
Vector3 temp_out_sphere = Random.onUnitSphere;//返回球表面某一点
Vector3 temp_in_sphere = Random.insideUnitSphere;//返回圆内某一点
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: