Vector3 desiredPosition = circle.position;
Vector3 smoothedPosition = Vector3.Lerp(mCamera.transform.position, desiredPosition, smoothSpeed);
mCamera.transform.position = smoothedPosition;
摄像机跟随UI移动
public class CameraFollowUI : MonoBehaviour
{
public Transform targetUI; // UI的Transform组件
public Vector3 offset = new Vector3(0f, 0f, -10f); // 摄像机相对于UI的偏移
public float smoothTime = 0.3f; // 平滑时间
private Vector3 velocity = Vector3.zero; // 用于SmoothDamp的速度变量
void Update()
{
if (targetUI != null)
{
// 获取UI的位置并加上偏移
Vector3 targetPosition = targetUI.position + offset;
// 使用SmoothDamp函数平滑移动摄像机的位置
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
}
}
}