【发布时间】:2022-01-15 18:25:37
【问题描述】:
这让我作为初学者/学习编码员感到沮丧。我一直在努力做到这一点,所以当我的游戏使用异步方法完成加载时,它会加载一个按钮,以便您继续。相反,它完全忽略了该功能,导致按钮仍然在游戏中,并且当您过早按下它时会出现故障。我的代码就在这里;我该如何解决这个问题?
IEnumerator LoadSceneAsynchronously(int levelIndex)
{
AsyncOperation operation = SceneManager.LoadSceneAsync(levelIndex);
while (!operation.isDone)
{
Debug.Log(operation.progress);
loading.GetComponent<Animator>().Play("loading");
text.GetComponent<Animator>().Play("idle");
yield return null;
}
if (!operation.isDone)
{
yield return new WaitForSeconds(5);
loading.GetComponent<Animator>().Play("loading disappear");
text.GetComponent<Animator>().Play("appear text");
text.GetComponent<Animator>().Play("blink text")
yield return null;
}
}
public void DestroyLoading()
{
gameObject.SetActive(false);
GameIsDoneLoading = true;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && !GameIsDoneLoading == true)
{
Debug.Log("Space key was pressed.");
text.GetComponent<Animator>().Play("disappear text");
logo.GetComponent<Animator>().Play("fpsa logo disappear");
}
}
【问题讨论】:
标签: c# unity3d asynchronous