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

}

}

}

相关推荐
WarPigs2 天前
Unity无法修改Assembly-CSharp.csproj错误
unity
FairGuard手游加固2 天前
手游加固怎么做?SO、IL2CPP、AssetBundle 与运行时保护详解
安全·游戏·unity
阿松爱学习3 天前
【Unity开发】监听Scene场景事件
unity·c#
xiaogai_gai4 天前
BOM 物料清单同步实战:金蝶云星空 → 四化智造 MES 修改场景深度拆解
unity·游戏引擎
淡海水4 天前
03-03-架构篇-SGen GC架构解析
unity·架构·c#·gc·sgen
/**书香门第*/4 天前
Cocos Creator 打螺丝游戏的实现
游戏引擎·cocos2d·螺丝·打螺丝
萌萌的提莫队长5 天前
Unity相机捕捉,图像识别,抠像+合成
opencv·unity
mxwin5 天前
Unity Shader 光线追踪原理与实战案例
unity·游戏引擎
地狱为王6 天前
Unity使用DPDFNet实现实时语音增强(降噪)
unity·语音增强·降噪·dpdfnet
平行云PVT6 天前
国产信创实时云渲染解决方案:如何实现数字孪生与三维应用云化部署?
unity·webrtc·unreal engine·实时云渲染·国产信创·摩尔线程·砺算科技