- Edited
Hi! I am trying to find out how to make universal Game Over screen button to return to previous screen that played and to restart it.
Currently I have function on my enemy that after collision with player, signals out the ouch method in player.
Enemy on_body_entered signal code:
func _on_sides_checker_body_entered(body): body.ouch(position.x) $SoundHurt.play()
And on player connected code:
func ouch(var enemyposx): set_modulate(Color(1,0.3,0.3,0.5)) velocity.y = JUMPFORCE * 0.4 if position.x < enemyposx: velocity.x = -400 elif position.x > enemyposx: velocity.x = 400 Input.action_release("left") Input.action_release("right") $Timer.start()
Which also starts timer that changes to Game Over screen, like this:
func _on_Timer_timeout(): get_tree().change_scene("res://GameOver.tscn")
And than on Game Over screen there are two buttons, and this is the complete code for each button:
Main Menu button:
extends Button func _on_MainMenuButton_pressed(): get_tree().change_scene("res://TitleMenu.tscn")
& Retry level button:
extends Button func _physics_process(delta): if Input.is_action_just_pressed("jump"): get_tree().change_scene("res://Level1.tscn") func _on_Retry_pressed(): get_tree().change_scene("res://Level1.tscn")
So my problem is that this way I'll need to create separate Game Over screen for each level (and there are 21 levels in the game) and I'm trying to find the way with one Game Over screen that will on Retry button pressed, always return to the previously played level, not just to the first one.
In case you need more information for answer, feel free to ask and thank you so much in advance for your answers.