unity3d day4(Time 类、Random 类 、Mathf 类)

一、Time 类

  作用:保证对象匀速移动。Time.deltaTime

  1.用来控制移动速度

  2.解决 Update()方法由于帧率的影响导致每一帧移动时时间不同的情况。

在Translate()方法中使用

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TimeDemo : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {

        this.transform.Translate(Vector3.up * Time.deltaTime);

	}
}

 在Rorate()方法中使用

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TimeDemo : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {

        this.transform.Rotate(Vector3.down * Time.deltaTime);

	}
}

猜你喜欢

转载自www.cnblogs.com/wxd623510693/p/11109620.html
今日推荐