Here is the full error:
E 0:00:05.192 get_node: (Node not found: "TimeBeforeGameOver" (relative to "/root/Player").)
<C++ Error> Condition "!node" is true. Returned: nullptr
<C++ Source> scene/main/node.cpp:1325 @ get_node()
<Stack Trace> Area2D.gd:21 @ _process()
Here is my code:
extends Area2D
#onready var explosion1 = preload("res://Explosion1.tscn")
var hp = 3
var isDead = false
func _on_Area2D_area_entered(area: Area2D) -> void:
if area.collision_layer == 2:
Player.hp -= 1
func _process(delta: float) -> void:
if hp <= 0:
# var explosion = explosion1.instance()
# get_parent().add_child(explosion)
# explosion.global_position = global_position
Player.isDead = true
if Player.isDead == true:
$TimeBeforeGameOver.start(1)
func _on_TimeBeforeGameOver_timeout() -> void:
get_tree().change_scene("res://GameOver.tscn")
Here is my world structure:
- Game
- BG
- SpawnTimer
- Player
- BulletDestroyer
- UI
- Score
And here is my player structure:
- Player
- Area2D
- CollisionShape2D
- TimeBeforeGameOver
- BulletSpawnPoint
- Front
- FireDelayTime
- CollisionShape2D