Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ThreeSpark |
I am having trouble with add_child(). I am trying to make it so that when the timer stops, one of three different warnings is added. For some reason, no warnings are added. Can someone help me? Here is my code:
extends Node2D
const warning1 = preload("res://Warning1.tscn")
const warning2 = preload("res://Warning2.tscn")
const warning3 = preload("res://Warning3.tscn")
func _ready():
$Timer.start()
func _process(delta):
if $Timer.wait_time <= 1:
return
$Timer.wait_time -= 0.0002
func _on_Timer_timeout():
randomize()
var choice = rand_range(0, 4)
if choice == 1:
var Warning1 = warning1.instance()
add_child(Warning1)
if choice == 2:
var Warning2 = warning2.instance()
add_child(Warning2)
if choice == 3:
var Warning3 = warning3.instance()
add_child(Warning3)