我正在尝试使用 Unity 和 C# 创建打砖块 3d 游戏。我创建了简单的菜单(场景 0),在那里我可以开始我的游戏,我的主要场景是实际游戏发生的场景(场景 1)和记分板(场景 2),它在玩家开始时失去所有 3 个球后显示。按任意键后,我返回菜单并可以再次开始游戏。这就是问题开始的地方。
在丢掉第一球后的第二场比赛中,我的比赛变得疯狂。我得到了很多“MissingReferenceException”,如下所示(但有些链接到其他对象(如 GUIText 等):
MissingReferenceException: The object of type 'Player' has been destroyed but
you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
Player.BallLost () (at Assets/Player/Player.cs:164)
GameEventManager.TriggerBallLost () (at Assets/Menagers/GameEventManager.cs:30)
Ball.Update () (at Assets/Ball/Ball.cs:47)
Run Code Online (Sandbox Code Playgroud)
我注意到由于未分配变量而导致的大量 MissingReferenceExceptions。但这对我来说感觉有点不同,因为它在“第一场比赛”期间一切正常。什么会导致这个问题?在为第二个游戏启动游戏后,我检查了检查员,所有变量都分配给了对象。
我不确定是否应该插入游戏代码,因为它已经变得相当大并且被分成 > 10 个脚本。