unity中摄像机跟随

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);

}

}

}

相关推荐
野奔在山外的猫8 小时前
【解决】解决方案内存在对应命名空间,但程序引用显示无该命名空间问题
unity
B0URNE8 小时前
【Unity基础详解】(5)Unity核心:Coroutines协程
unity·游戏引擎
野奔在山外的猫11 小时前
【案例】程序化脚本生成
unity
xiaotao13113 小时前
unity hub在ubuntu 22.0.4上启动卡住
ubuntu·unity·游戏引擎
小句15 小时前
通过图表和详细流程解释XXL-JOB中任务从创建到执行的完整过程
unity·游戏引擎
!chen2 天前
Unity颜色曲线ColorCurves
unity·游戏引擎
B0URNE2 天前
【Unity基础详解】(4)Unity核心类:MonoBehaviour
unity·游戏引擎
AA陈超2 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-29 属性信息委托
c++·游戏·ue5·游戏引擎·虚幻
AA陈超2 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-31 映射标签到属性
c++·游戏·ue5·游戏引擎·虚幻
gshh__2 天前
SuperMap Hi-Fi 3D SDK for Unreal 使用蓝图接口加载多源数据
ue5·游戏引擎·supermap