我有一個球并希望主攝像機跟隨它,所以我在攝像機上附加了一個腳本:
public class Tracker : MonoBehaviour
{
public GameObject target;
void Update()
{
this.transform.position = Vector3.Lerp(this.transform.position, target.transform.position, .5f);
}
}
目標是球游戲物件。我希望相機具有與球相同的 x 和 y 坐標,但保持其原始 Z。
不知道該怎么辦,也許有不同的方法來解決這個問題?
uj5u.com熱心網友回復:
您可以使用建構式創建運動 Vector3,例如:
Vector3 newPos = new Vector3(target.transform.position.x,target.transform.position.y, transform.position.z);
this.transform.position = Vector3.Lerp(this.transform.position, newPos, .5f);
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/351163.html
上一篇:第1062回
下一篇:敵人射擊本身-UnityC#
