unity中使用LoadScene卡住不执行原因分析

问题描述:

执行重启仿真时候,会卡住,像图里这样,代码如下图所示

声明:

socket_controller.restart就是一个布尔类型的变量

如果if(socket_controller.restart)为真的时候,就执行SceneManager.LoadScene(0);

 尝试过的方法:

把if条件语句写到start,这样也不行,导致整个函数都不再执行。

问题原因:

就是socket_controller.restart一直等于true,导致SceneManager.LoadScene(0)一直在执行

解决方法:

if(socket_controller.restart)//重启仿真
{
SceneManager.LoadScene(0);
socket_controller.restart=false;
}

即执行完一次函数之后把socket_controller.restart=false;

 

原文地址:https://www.cnblogs.com/redzzy/p/13968127.html