delayed instancing node :3
This commit is contained in:
parent
dab1509a5e
commit
38e60fad93
2 changed files with 29 additions and 0 deletions
23
objects/delayed_instance.gd
Normal file
23
objects/delayed_instance.gd
Normal file
|
@ -0,0 +1,23 @@
|
|||
extends Node
|
||||
|
||||
export var delay = 0.0
|
||||
export var autostart = false
|
||||
|
||||
var children = []
|
||||
|
||||
func _enter_tree():
|
||||
for child in get_children():
|
||||
children.append(child)
|
||||
remove_child(child)
|
||||
|
||||
func _ready():
|
||||
if autostart:
|
||||
start()
|
||||
|
||||
func start():
|
||||
get_tree().create_timer(delay).connect("timeout", self, "_instance_children")
|
||||
|
||||
func _instance_children():
|
||||
var parent = get_parent()
|
||||
for child in children:
|
||||
parent.add_child(child)
|
6
objects/delayed_instance.tscn
Normal file
6
objects/delayed_instance.tscn
Normal file
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://objects/delayed_instance.gd" type="Script" id=1]
|
||||
|
||||
[node name="DelayedInstance" type="Node"]
|
||||
script = ExtResource( 1 )
|
Loading…
Add table
Add a link
Reference in a new issue