简体   繁体   English

运行游戏时,我的Prefab从脚本中消失了吗?

[英]My Prefab disappears from script when I run the game?

I have Script attached on my Player, that script has Public GameObject variable.When I attach my Prefab to it and run game it disappears from script ? 我在Player上附加了脚本,该脚本具有Public GameObject变量。当我将Prefab附加到它并运行游戏时,它从脚本中消失了?

I add my prefab to script 我将预制件添加到脚本中

When I run the game it just disappears !!?? 当我运行游戏时,它就消失了!

在此处输入图片说明

您所连接的炸弹预制件必须位于资产文件夹下,而不是在场景下,我的意思是,当您单击分配给它的炸弹时,它必须打开“项目”选项卡并显示给您,如果它仅存在于场景中,它将是消失了

It could be that the bomb prefab you are assigning to your public GameObject variable is somehow being destroyed when you start the game. 您分配给公共GameObject变量的炸弹预制件可能在启动游戏时以某种方式被破坏。

For example: 例如:

public GameObject other;

private void Awake()
    {
        Destroy(other);
    }

Check to see if you have any Destroy functions that could be causing the prefab to be destroyed. 检查是否有任何破坏功能可能会导致预制件被破坏。

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

相关问题 我无法在 Unity 中为我的预制件分配脚本 - I cannot assign a script to my prefab in Unity 如何使同一Prefab的实例的行为与游戏中的其他实例不同? - How can I make an instance of the same Prefab behave differently from other instances in my game? 如何让游戏对象将更改应用于脚本中的预制件 - how do i get a game object to apply changes to a prefab in script 在我的脚本中激活GameObject预制时未显示在场景中 - GameObject prefab is not showing in scene when activated in my script 在沙盒游戏的鼠标位置实例化预制件 - Instantiating a prefab at the mouse position for my sandbox game 使用 ac#script 更改预制件的颜色时,它会显示在检查器中,但不会显示在游戏视图中 - When changing the colour of a prefab using a c#script, it shows in the inspector but not in the game view 使用脚本重新定位后,精灵对象从游戏选项卡中消失 - Sprite object disappears from the game tab after repositioning with script 加载预制件时如何修复游戏冻结 - How to fix game freeze when loading prefab 我如何在我刚刚实例化的预制组件中引用场景中的游戏 object? - How can I reference a game object on my scene in a prefab component I have just instantiated? 如何在触发器上加载预制件以便我的游戏继续进行? - How can I load in a prefab on trigger so my game keeps going?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM