UI GameObject可以在Scene View中显示,但是在Game View不能显示

这篇具有很好参考价值的文章主要介绍了UI GameObject可以在Scene View中显示,但是在Game View不能显示。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

出现UI GameObject可以在Scene View中显示,但是在Game View不能显示这种问题,可能有很多种原因,例如Layer设定、Camera Clipping设定、font assets等问题。 对于TextMeshPro,还有Material Set的问题,见这篇文章。

而我这次遇到的,是因为我没有把UI GameObject放到UI Canvas上面。如下图所示,我的游戏的界面是在左下角很小的部分,而Canvas很大,但是没有完全覆盖住我的游戏界面。当我把UI GameObject放在了我的游戏界面,但是没有在Canvas里面的时候,UI就不会显示。
unity scene显示game不显示,Unity C#开发语法,ui,unity,游戏引擎
解决办法是,修改Canvas的Render mode: 从默认的Screen Space-Overlay (即上图展示的Canvas,无法修改位置和大小)修改至World Space。其他的部分(例如游戏界面和代码逻辑)均无须修改,就可以了。

unity scene显示game不显示,Unity C#开发语法,ui,unity,游戏引擎

关于Unity中的troubleshooting

在Unity中,当一个功能没有像预期的一样正常运行时,找到原因是很难的一件事情,因为有很多地方可能导致了没有正常运行。对于初学者而言,则更难,因为都不知道有哪些地方可能是原因。

除了多多积累之外,一种troubleshooting的思路是,“对比实验”。即,想办法找到正常工作的情况,然后将自己的异常情况和正常情况对比,看看哪里设置不一样。例如,在解决UI无法正常显示这个问题时,我就是试了很多改变,例如在新的Scene里面测试UI是否能正常显示、将某些GameObject Disable等等,然后找到了原因:原来是UI没有放进Canvas。

Canvas的三种Render Mode

(The following content is created by a LLM.)

Screen Space - Overlay: This is the default render mode for Canvas. In this mode, the UI elements are rendered on top of everything else in the scene, akin to an overlay. The Canvas is always the same size as the screen and it doesn’t move or rotate, so UI elements maintain the same size and position regardless of camera position or settings. This mode is best used for UI elements that need to always be visible and in the same place, such as health bars, score displays, or menus.

Screen Space - Camera: In this mode, the Canvas behaves similarly to Screen Space - Overlay, but the UI elements are rendered at a certain distance from a specified camera. They will appear to move, rotate, and scale with the camera, and they can be obscured by other objects in the scene based on their Z position. This mode is useful if you want to have UI elements that are attached to a specific camera, like a heads-up display (HUD) that moves with a player’s first-person perspective.

World Space: In this mode, the Canvas behaves like any other object in the scene. It can be moved, rotated, and scaled freely, and UI elements can interact with lights and be affected by perspective. This mode is useful when you want to integrate UI elements into the game world itself, like text bubbles over a character’s head or interactive buttons within the environment.

The appropriate mode to use depends on the needs of your game. If you have UI elements that need to be always visible and don’t interact with the game world, use Screen Space - Overlay. If you have UI elements that are attached to a specific camera view, use Screen Space - Camera. And if you have UI elements that are integrated into the game world, use World Space.

Unity的坐标系统、Tilemaps and Canvas

(The following content is created by a LLM.)

Unity’s Coordinate System: Unity uses a left-handed coordinate system. The center of the world is at (0, 0, 0). In a 2D game, positive X values go to the right, positive Y values go up, and positive Z values come out of the screen.

Tilemaps: Unity’s Tilemap system creates 2D tile-based environments. The Tilemap’s position refers to the cell at the origin (0, 0) of its grid.

Canvas and TextMeshPro: In Unity, all UI elements must be children of a Canvas. If you’re placing a TextMeshPro element in a 2D game world (and not as an overlay on the screen), you’ll want to use a Canvas in “World Space” mode. This makes the Canvas act like any other object in the world, so you can place it anywhere, and its children will follow its position, rotation, and scale.文章来源地址https://www.toymoban.com/news/detail-717257.html

到了这里,关于UI GameObject可以在Scene View中显示,但是在Game View不能显示的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • unity 模型在scene场景中看不到,在game视图可见

    这个问题出现的原因是:在编辑器中进行了如下设置:  上图左侧的眼睛图标的作用就是显示或隐藏物体。 另一种情况: 这是对层级的显示或隐藏。  

    2024年02月09日
    浏览(21)
  • u-view使用轮播组件u-swiper不能正常显示

    写了半天一直显示的是播放视频,但是我的路径是图片,一直黑屏 Swiper 轮播图 | uView 2.0 - 全面兼容nvue的uni-app生态框架 - uni-app UI框架  设置type类型

    2024年02月11日
    浏览(28)
  • Unity3d中Scene场景2D模式下放大后UI元素后不显示的问题

    如题:UI在game视图显示没有问题, 在Play状态下,在Sence视图查看UI对象的时候进行放大操作,然后UI就不显示了或者显示不全,缩小就恢复正常。这让我在Play模式下预览UI状态很麻烦。相关问题描述较少。 初步判定为摄像机问题,但我们的项目最近并没有对相机进行过什么调

    2024年02月03日
    浏览(45)
  • 初识Unity——创建代码、场景以及五个常用面板(创建C#代码、打开代码文件、场景的创建、Project、Hierarchy、Inspector、Scene、Game )

    目录 创建代码 创建C#脚本 打开代码文件 可能出现的问题 场景 场景的创建 基本介绍 五个窗口面板的作用 Project Hierarchy Inspector Scene Game  从unity2018版本开始,unity就开始不再维护和推荐JavaScript for Unity以及Boo等语言,现在官方主推和最常用的脚本语言是C#。 创建一个脚本之后

    2024年02月07日
    浏览(35)
  • 电脑可以连接wifi,甚至可以qq聊天,但就是不能用浏览器上网,一直显示未检测出入户网线的解决方案

    今天回到家,准备办公却发现电脑可以连接wifi,甚至可以qq聊天,但就是不能用浏览器上网,一直显示未检测出入户网线的解决方案,小白也可以看懂 以下有几种解决方案,不妨都试试,估计可以解决95%的相关问题 打开浏览器的菜单 (以谷歌为例,其他浏览器都差不多的步

    2024年01月22日
    浏览(146)
  • QT GUI代码大全(MainWindow, QFile, QPainter, QGraphicsItem/Scene/View)

    QMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()) void setCentralWidget(QWidget *widget); //set the given widget to the main window’s central widget void setFixedSize(int w, int h); //set the size of the widget void setWindowIcon(QIcon(QString filepath)); QMenuBar *QMainWindow::menuBar() const 返回MainWindow的menu bar //c

    2024年02月03日
    浏览(27)
  • SpringBoot集成Swagger UI显示的接口可以显示Json格式的信息说明

           Swagger是一个规范且完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。        使用 Swagger 后可以直接通过代码生成文档,不再需要自己手动编写接口文档,对程序员来说非常方便,可以节约写文档的时间去学习新技术。        提供 Web 页面在

    2024年04月11日
    浏览(27)
  • 论文阅读《Block-NeRF: Scalable Large Scene Neural View Synthesis》

    论文地址:https://arxiv.org/pdf/2202.05263.pdf 复现源码:https://github.com/dvlab-research/BlockNeRFPytorch   Block-NeRF是一种能够表示大规模环境的神经辐射场(Neural Radiance Fields)的变体,将 NeRF 扩展到渲染跨越多个街区的城市规模场景。该方法将场景分解为单独训练的 NeRF,使渲染时间与

    2024年02月03日
    浏览(31)
  • Shader for Quest 2: 自定义shader在Unity Editor中可以使用,但是在Quest 2中却不可以

    上面这份代码,在Unity Editor中可以使用,但是编译到Quest 2之后,却没有反应。这可能是由于多种原因引起的,可以按照下面的步骤修改。 The Oculus Quest 2 primarily uses OpenGL ES and Vulkan. 如果使用Visual Studio联调的话,可能会看到这个报错: System.ArgumentNullException: Value cannot be null.

    2024年04月29日
    浏览(23)
  • RPG项目01_UI面板Game

    基于“RPG项目01_技能释放”,将UI包导入Unity场景中, 将图片放置 拖拽 取消勾选(隐藏攻击切片) 对技能添加蒙版 调节父子物体大小一致 将子类蒙版复制 执行5次 运行即可看到技能使用完的冷却条 在Scripts下创建UI文件夹 写代码: using System.Collections; using System.Collections.Ge

    2024年02月04日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包