Unity 重新加载场景报错:MissingReferenceException

MissingReferenceException: The object of type 'SpawnEnemy' 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.

原因是我的SpawnEnemy脚本开启了协程,而我重新加载了该场景后原先正在执行的协程引用了其他的对象,而重新加载场景后,原先访问的一些对象会被销毁(所以是因为其他对象比协程先销毁?)。于是会报这个错。

在重新加载场景时暂停该脚本所有协程即可。

猜你喜欢

转载自blog.csdn.net/qq_50906930/article/details/125380951