简体   繁体   English

游戏对象出现在场景视图中但不在游戏视图中

[英]Game Object Appears in Scene View but not in Game View

Seems like I am missing something here, using latest version of unity and I am instantiating a gameobject on click.. It appears fine in scene View but not in the game view?好像我在这里遗漏了一些东西,使用最新版本的 unity,我在点击时实例化一个游戏对象。它在场景视图中看起来很好,但在游戏视图中却没有?

I have googled it and tried all those responses.我用谷歌搜索并尝试了所有这些回复。

I checked the layers at the top right of the screen, They are all showing, Also the z value is lower than the cameras' But honestly i have tried having them at nearly all z positions.我检查了屏幕右上角的图层,它们都在显示,z 值也低于相机的值,但老实说,我已经尝试在几乎所有 z 位置放置它们。

The game object i am spawning is a sprite with a rigid body, but that shouldn't matter right?我生成的游戏对象是一个刚体的精灵,但这应该无关紧要吧? It shows up in scene view and game view should just show me what the scene does?它出现在场景视图中,而游戏视图应该只显示场景的作用?

Any ideas?有任何想法吗?

This is a pretty old question but I just had the same issue.这是一个很老的问题,但我遇到了同样的问题。 I solved it by playing around with the camera clipping planes.我通过摆弄相机剪裁平面来解决它。

To test if this is the case, hit play and when the object is supposed to be in view, hit pause.要测试是否是这种情况,请点击播放,当对象应该在视野中时,点击暂停。

Select the camera from the hierarchy and try altering the clipping planes - "Near" and "Far" properties from the inspector.从层次结构中选择相机并尝试更改剪裁平面 - 检查器中的“近”和“远”属性。

If this works then don't forget to make the same changes again after the game has stopped running - They reset to the way they were before you hit play.如果这有效,那么不要忘记在游戏停止运行后再次进行相同的更改 - 它们会重置为您点击播放之前的状态。

I think this is to do with the distance from the camera that objects have to be, in order to be rendered.我认为这与物体必须与相机的距离有关,以便进行渲染。 Its probably useful with fog etc. but I'm kinda new to Unity so could be wrong.它可能对雾等有用,但我对 Unity 有点陌生,所以可能是错误的。

I tried posting a screenshot but apparently you're not allowed to help properly if you're new on here :s.我尝试发布屏幕截图,但显然,如果您是新来的,则不允许您提供适当的帮助:s。 probably to prevent spam etc.可能是为了防止垃圾邮件等。

Anyway, hope this helps someone out there :)无论如何,希望这可以帮助那里的人:)

统一截图

It can happen for may problems它可能发生在可能的问题上

1. Culling mask problem: 1.剔除掩码问题:

just check it, it is set to everything or not只需检查它,它是否设置为所有内容

剔除面具

2. Far Near problem: 2.远近问题:

Solve it by changing their values.通过改变它们的值来解决它。 I can't say about any specific values cause it varies from problem to problem我不能说任何特定的值,因为它因问题而异

远近问题

3.Layer Problem: 3.图层问题:

this problem specially happen when you a create a new scene on unity but it can happen for many reasons当您在 unity 上创建新场景时会特别发生此问题,但可能由于多种原因而发生

To solve this为了解决这个

  • Click on layers点击图层
  • Set everything visible设置一切可见

在此处输入图片说明 在此处输入图片说明

在 MainCamera 或 Camera 的 Inspector 上,您会找到称为“深度”的东西,只需将其设置为与您的视野相同的值即可:)

By default in a 2D scene the camera is pointing to positive Z and it is located at (0 1 -10).默认情况下,在 2D 场景中,相机指向正 Z 并且位于 (0 1 -10)。 This means that the Z position of the sprite needs to be higher than cameras Z position, not lower.这意味着精灵的 Z 位置需要高于相机 Z 位置,而不是更低。

Also check that Sprite Renderer of the sprite is enabled in the "Inspector" view.还要检查是否在“检查器”视图中启用了精灵的精灵渲染器。

If those doesn't help I would suggest starting to remove other GameObjects at run time to see if the sprite is behind something.如果这些没有帮助,我建议在运行时开始删除其他游戏对象,以查看精灵是否在某些东西后面。 Just click on a GameObject at "Hierarchy" view and hit delete key.只需在“层次结构”视图中单击一个游戏对象,然后按删除键即可。

Hopefully some of these help you to find the problem.希望其中一些可以帮助您找到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM