简体   繁体   English

为什么使用 Instantiate 生成的游戏对象在游戏中不可见,但在我按统一播放时在场景中可见(2d 游戏)

[英]why are the spawned game objects with Instantiate are invisible in game but visible in scence when i press play in unity (2d game)

在此处输入图像描述

I don't know what can cause this problem , those game objects : enemy (spawned) can't see them in game I need your help thanks in advance .我不知道是什么导致了这个问题,那些游戏对象:敌人(生成的)在游戏中看不到它们我需要你的帮助提前谢谢。

There could be many issues as we don't have very much information.可能有很多问题,因为我们没有太多信息。 First make sure the instantiated objects' Z coords are in front of the Camera and not behind the backround.首先确保实例化对象的 Z 坐标在相机前面,而不是在背景后面。

If they are sprites, the 'Order in Layer' property may be set up wrong.如果它们是精灵,“层中的顺序”属性可能设置错误。 If you never changed the layer order, they will all be 0s, and can therefore appear in any layering.如果您从未更改过层顺序,它们将全部为 0,因此可以出现在任何分层中。 In this case, the background appears on top of the sprites, because it doesn't know which to render in front.在这种情况下,背景出现在精灵的顶部,因为它不知道在前面渲染哪个。 Change your ghosts to have a value of 1, and the background to be 0, and they will appear in front将你的鬼魂的值改为1,背景为0,它们会出现在前面

There are some possibilities:有一些可能性:

  • The object is too close to the camera.物体离相机太近。 In this caso you can try to reduce the camera's near distance.在这种情况下,您可以尝试减少相机的近距离。 Also they can be very far, so you would have to increase far's distance.它们也可能很远,所以你必须增加远距离。

  • When sprites are in the same layer, they might appear randomly in front or behind the others.当精灵在同一层时,它们可能会随机出现在其他精灵的前面或后面。 If this is the case, try to let the players' order in layer bigger than the background order in layer.如果是这种情况,请尽量让玩家在图层中的顺序大于背景在图层中的顺序。

  • The objects might be in a layer that the camera doesn't render.对象可能位于相机不渲染的图层中。 In the property Culling Mask of the camera, check if the layer of your objects is marked.在相机的属性 Culling Mask 中,检查对象的图层是否被标记。

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

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