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

相关推荐

  1. unity摄像机跟随

    2024-03-10 00:22:05       22 阅读
  2. unity计算摄像机水平FOV的公式是什么

    2024-03-10 00:22:05       10 阅读
  3. unity canvas下物体的朝向跟随

    2024-03-10 00:22:05       40 阅读
  4. Unity相机跟随角色移动

    2024-03-10 00:22:05       36 阅读
  5. Unity 摄像机组件】Camera场景摄像机的认识

    2024-03-10 00:22:05       35 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-10 00:22:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-10 00:22:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-10 00:22:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-10 00:22:05       20 阅读

热门阅读

  1. Error running ‘Attach debug to process‘

    2024-03-10 00:22:05       26 阅读
  2. BDD测试框架Cucumber学习

    2024-03-10 00:22:05       23 阅读
  3. C# 的一些好用的语法糖介绍

    2024-03-10 00:22:05       21 阅读
  4. linux脚本练习2-文件压缩删除

    2024-03-10 00:22:05       20 阅读
  5. 铭文资产是比特币生态破局者 or 短暂热点?

    2024-03-10 00:22:05       20 阅读
  6. 数据结构-二分查找

    2024-03-10 00:22:05       22 阅读
  7. 如何更好的理解设计模式之桥接模式

    2024-03-10 00:22:05       21 阅读
  8. golang从0到1实战系统四十:处理表单的输入

    2024-03-10 00:22:05       24 阅读
  9. YUNBBE云贝:PG表空间介绍

    2024-03-10 00:22:05       26 阅读
  10. Promise介绍

    2024-03-10 00:22:05       26 阅读