Question by
CoolBoy241 · Nov 28, 2021 at 12:34 PM ·
animationunityeditorkeyboard inputloading screenasynchronous
how do i make something available when my game is done doing an async operation?
i've been trying to make it so that when the game fully loads, you can press the space bar to continue. instead, it ignores the function altogether, causing the animation to play early and to glitch out when you press the spacebar while the game is loading. here is my code, how can i fix this?
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");
}
}
i have also tried enabling the boolean value in "if (!operation.isDone)" and tried to track the operation's progress in update.
Comment