2 回答
TA贡献1862条经验 获得超7个赞
我认为你的问题出在你的Pause方法上:
public void Pause() //Function to take care of Pause Button..
{
print("Entered Pause Func");
if (Time.timeScale == 1 && paused == false) //1 means the time is normal so the game is running..
{
print("Enterer first if");
Time.timeScale = 0; //Pause Game..
}
if (Time.timeScale == 0)
{
Time.timeScale = 1; //Resume Game..
}
}
如果您输入if您设置的第一个语句Time.timeScale = 0- 然后您立即进入第二个if并将其设置回 1。
试试这个 -一旦它设置为 0,它就returns来自Pause方法Time.timeScale。
public void Pause() //Function to take care of Pause Button..
{
print("Entered Pause Func");
if (Time.timeScale == 1 && paused == false) //1 means the time is normal so the game is running..
{
print("Enterer first if");
Time.timeScale = 0; //Pause Game..
return;
}
if (Time.timeScale == 0)
{
Time.timeScale = 1; //Resume Game..
}
}
如果您想要在Pause方法中做的唯一两件事是将 设置Time.timeScale为 0 或 1,您甚至可以将其简化为:
public void Pause() //Function to take care of Pause Button..
{
print("Entered Pause Func");
if (Time.timeScale == 1 && paused == false) //1 means the time is normal so the game is running..
{
print("Enterer first if");
Time.timeScale = 0; //Pause Game..
}
else
{
Time.timeScale = 1; //Resume Game..
}
}
TA贡献1784条经验 获得超8个赞
如果你的第一个条件if语句true然后设置你timeScale要0那么第二个条件if变得true那么你将其设置回1
您应该只是你的第二个改变if成else if这样,如果第一个条件就是true那么你的程序不会检查第二个。
public void Pause()
{
if (Time.timeScale == 1)
{
Time.timeScale = 0;
}
else if (Time.timeScale == 0)
{
Time.timeScale = 1; //Resume Game..
}
}
- 2 回答
- 0 关注
- 324 浏览
添加回答
举报