so I’m trying to get an explosion animation when I press one of the play buttons and then the game scene starts. I know I probably have to use callback functions, but I have no idea how and I can’t find it online. Under here is the code I think it has to be in.
public void Start()
{
GameObject.FindGameObjectWithTag("gameMusic").GetComponent<MusicClass>().PlayMusic();
}
//starts gameMode
public void PlayGame (int gameMode = 0)
{
if (gameMode == 0)
{
// enable explosion
// callback function
SceneManager.LoadScene("ball");
}
if (gameMode == 1)
{
SceneManager.LoadScene("reverse");
}
if (gameMode == 2)
{
SceneManager.LoadScene("all ways");
}
if (gameMode == 3)
{
SceneManager.LoadScene("1-player");
}
if (gameMode == 4)
{
SceneManager.LoadScene("breakout");
}
if(gameMode == 5)
{
SceneManager.LoadScene("start menu");
}
}
//quits gameMode
public void QuitGame ()
{
Debug.Log("Quit");
Application.Quit();
}
You mean an explosion (or any kind of animation) WHILE the scene is loading? In that case look into async scene loading. Otherwise you’ll have to make sure to play that animation in the new scene, not the current one.
Async loading with Single loading mode will replace the current scene once loading finished as far as I understand, so there is no guarantee that the animation has finished by this time. With additive loading you can at least hide that scene‘s game objects and set them to active at a later time. But you‘d also have to ensure the current scene will work in companion with additively loaded scenes.
so I’m looking at your code and I am a bit confused what this bit under here means. does it play a bit of music when the button is pressed and then go to the new scene? is ‘ButtonAudioClip’ the music? what does PlayOneShot mean?