system
1
|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
DJSlimeball |
Sorry if this is REALLY stupid, I’m not good.
extends Area2D
var timer = Timer.new()
func _on_[COIN]_body_entered(body: Node) -> void:
queue_free()
get_parent().get_parent().get_node("Node2D/[COIN]Counter/UI").show()
if get_parent().get_parent().get_node("Node2D/[COIN]Counter/UI").show():
timer.connect("timeout",self,"do_this")
timer.wait_time = 3
timer.one_shot = true
add_child(timer)
timer.start()
func do_this():
get_parent().get_parent().get_node("Node2D/[COIN]Counter/UI").hide()
[COIN]
is just a placeholder to make this more readable, if that’s possible.
system
2
|
|
|
|
Reply From: |
exuin |
Queue free deletes the node and its children, including the timer, so it never times out.
How would I go about rearranging this or changing it to make it only delete the collectible? Thanks.
P.S. Sorry for the late response.
DJSlimeball | 2022-12-04 09:22
hide the coin instead of deleting it, and then free it when the timer times out
The other comment has been hidden, cuz’ I actually figured THE WHOLE THING out:
extends Area2D
var timer = Timer.new()
func _on_GeluLumenLapis_body_entered(body: Node) -> void:
hide()
$CollisionShape2D.set_deferred("disabled", true)
get_parent().get_parent().get_node("Node2D/LapisCounter/UI").show()
timer.connect("timeout",self,"do_this")
timer.wait_time = 3
timer.one_shot = true
add_child(timer)
timer.start()
func do_this():
get_parent().get_parent().get_node("Node2D/LapisCounter/UI").hide()
queue_free()
Thanks for the help, though.
EDIT: Better code that doesn’t break when touching a second collectible.
DJSlimeball | 2022-12-06 02:20