Application.Load() issue

Hey guys,

Now that no one can answer right my alternative question on how to simulate a button press I wanted to exactly call a function that changes some values in order to skip the start menu and to get to the actual game (retry-button).

My game consists of only 1 scene. When the game starts, the user sees a game menu.

On this is a play button which starts the arcade game itself. If the player lose, a retry and menu button will appear,

  • the menu button just reloads the whole scene since the scene starts with it. (done)

  • The retry button however needs to restart the scene and simulate the play button press which triggers the starting of the arcade game automatically.

For that the player needs to turn interactable and the menu should change from “Menu” (start menu) to “Game” (arcade game) as written in the OnRetrySinglePlayer()-function above.

I have a function that restarts my game and should skip the start menu like this:

function OnRetrySinglePlayer(){
	Application.LoadLevel(0);
    var cv = GameObject.Find("Canvas").gameObject;
  var game = cv.transform.FindChild("Game").GetComponent.<_Menu>() as _Menu;
    var player = GameObject.Find("Player").gameObject;

	cv.GetComponent.<MenuManager>().ShowMenu(game);
	player.transform.GetComponent.<Player>().Interactable();
    //b_play.transform.GetComponent.<UI.Button>().onClick.AddListener(0); //old way to call the onClick function in the button-component
}

This restarts only the scene with no errors.

I think the script itself reloads on Application.LoadLevel(0), so it never reaches further code.

Thanks in advance.

You changed the level, as script comes from other scene so of course reference is not linked. All what you have to do is find the reference.

You didn’t really specify what happens on level load, what scripts are reloaded, are there any tagged with dontdestroyonload, is it the same level and so on.
Who is Player, does it has something to do with question, if not why its mentioned? No wonder none answered your previous question.

Edit your question with required information.