DaPOPs
var hurt_timer = 0.0
var one_time_effect = false
func start(Delta):
if one_time == false:
Hurt_box.create_hit_effect()
is_active = true
one_time = true
if is_active:
hurt_timer += Delta
if hurt_timer >= 0.2:
hurt_timer = 0.0
one_time_effect = false
end()
Hit_box.collision_shape_2d.disabled = true
func end():
emit_signal("end_state")
is_active = false
one_time = false
1 - you don't need so many bools.
DaPOPs call a function "Hurt_box.create_hit_effect()" but I want it to be executed only once
do you want the thing to run every time the timer ends or just once and start over when pressing a button?
run every tick: just run it with end.
if hurt_timer >= 0.2:
hurt_timer = 0.0
one_time_effect = false
Hurt_box.create_hit_effect()
end()
run once: don't reset the variable after setting it to true, set it back to false from OUTSIDE THE SCRIPT
func end():
emit_signal("end_state")
is_active = false
#one_time = false
myScript.one_time = false
DaPOPs when you call the start() function again once end() has been executed, the hurtbox function can be called again.
but you are calling this thing every frame... it's doing what it's supposed to.
try putting the timer OUTSIDE the function and having it call the function instead:
if hurt_timer >= 0.2:
hurt_timer = 0.0
start()
edit:
xyz DaPOPs Use a timer to call end() after a certain time. All you need is one line of code:
get_tree().create_timer(.2).connect("timeout", end)
the timer has to run continuously, so use a timer node instead.