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

}

}

}

相关推荐
Y***K4344 小时前
C在游戏中的Godot
游戏·游戏引擎·godot
WarPigs15 小时前
Unity编辑器开发笔记
unity·编辑器·excel
Q***f63515 小时前
C++在游戏引擎开发中的实践
游戏引擎
6***x54515 小时前
C++在计算机视觉中的图像处理
c++·图像处理·计算机视觉·游戏引擎·logback·milvus
霜绛21 小时前
Unity:lua热更新(三)——Lua语法(续)
unity·游戏引擎·lua
世洋Blog1 天前
更好的利用ChatGPT进行项目的开发
人工智能·unity·chatgpt
evolution_language2 天前
Unity场景(Scene)的注意事项和易错点
unity·游戏引擎·scene
EQ-雪梨蛋花汤2 天前
【AI工具】使用 Doubao-Seed-Code 优化 Unity 编辑器插件:从功能实现到界面美化的完整实践
人工智能·unity·编辑器
g***B7382 天前
元宇宙游戏引擎
游戏引擎
Dr.勿忘2 天前
开源Unity小框架:高效单例与模块化设计
游戏·unity·开源·c#·游戏引擎·游戏程序·gamejam