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

}

}

}

相关推荐
dangoxiba11 小时前
【Unity学习心得】如何使用Unity制作“饥荒”风格的俯视角2.5D游戏
游戏·unity·c#·游戏引擎
cyr___14 小时前
Unity教程(十六)敌人攻击状态的实现
学习·游戏·unity·游戏引擎
优梦创客1 天前
《黑神话悟空》开发框架与战斗系统解析
unity·游戏开发·黑神话悟空·战斗系统·解包
仙魁XAN1 天前
Unity 设计模式 之 创造型模式-【工厂方法模式】【抽象工厂模式】
unity·设计模式·工厂方法模式·抽象工厂模式
我要吐泡泡了哦1 天前
GAMES104:15 游戏引擎的玩法系统基础-学习笔记
笔记·学习·游戏引擎
躺下睡觉~2 天前
Unity-Transform类-父子关系
java·unity·游戏引擎
躺下睡觉~2 天前
Unity-Transform类-缩放和看向
unity·游戏引擎
君莫愁。2 天前
【Unity】检测鼠标点击位置是否有2D对象
unity·c#·游戏引擎
咩咩觉主2 天前
Unity实战案例全解析:PVZ 植物卡片状态分析
unity·c#·游戏引擎
蓝裕安2 天前
伪工厂模式制造敌人
开发语言·unity·游戏引擎