简单粗暴点,直接甩代码。
public Transform target;//需要跟随的物体
float pos; //物体和相机之间的距离
public float smooth = 5.0F;
void FixedUpdate()
{
if (target.position.y > transform.position.y)
{
pos = target.position.y - this.gameObject.transform.position.y;
transform.position =Vector3.Lerp
(transform.position, new Vector3(transform.position.x, transform.position.y + pos, transform.position.z)
, Time.deltaTime * smooth);
}
}
时间: 2025-01-07 14:12:29