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

}

}

}

相关推荐
心之所向,自强不息2 小时前
【Unity Shader编程】之让画面动起来
unity·游戏引擎
不伤欣1 天前
游戏设计模式 - 子类沙箱
游戏·unity·设计模式
Magnum Lehar1 天前
vulkan游戏引擎test文件memory实现
游戏引擎
Magnum Lehar1 天前
vulkan游戏引擎test_manager实现
java·算法·游戏引擎
快乐觉主吖1 天前
Unity的日志管理类
android·unity·游戏引擎
WarPigs1 天前
Unity性能优化笔记
笔记·unity·游戏引擎
T.D.C2 天前
【业务框架】3C-相机-Cinemachine
unity
一线灵2 天前
跨平台游戏引擎 Axmol-2.6.1 发布
游戏引擎
Clank的游戏栈2 天前
Unity基于GraphView的可视化关卡编辑器开发指南
unity·编辑器·游戏引擎
海尔辛3 天前
Unity UI 性能优化--Sprite 篇
ui·unity·性能优化