📜  unity 获取对象的速度 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:55.150000             🧑  作者: Mango

代码示例1
public float speed;
public float speedPerSecond;
public Vector3 oldPosition;

void Update()
 {
     speed = Vector3.Distance(oldPosition, transform.position); //This is the speed per frames
       speedPerSecond = Vector3.Distance(oldPosition, transform.position) / Time.deltaTime; //This is the speed per second
     oldPosition = transform.position;
     Debug.Log("Speed: " + speed.ToString("F2"));
 }