46 lines
1.4 KiB
GDScript3
46 lines
1.4 KiB
GDScript3
extends Area2D
|
|
|
|
export(String) var hurtbox_entered_function = ""
|
|
|
|
var call_function: FuncRef
|
|
|
|
# Declare member variables here. Examples:
|
|
# var a = 2
|
|
# var b = "text"
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
if hurtbox_entered_function:
|
|
call_function = funcref(owner, hurtbox_entered_function)
|
|
else:
|
|
print("Warning: No hurtbox function defined on ", owner.name)
|
|
|
|
func set_hurtbox(enabled: bool):
|
|
for child in get_children():
|
|
if child is CollisionShape2D:
|
|
child.set_deferred("disabled", !enabled)
|
|
|
|
# Switching to a new model that starts with Hitbox
|
|
func on_hit(sender):
|
|
print("Received hit from: " + sender.owner.name)
|
|
if hurtbox_entered_function:
|
|
call_function.call_func(sender.damage_amount)
|
|
|
|
# This one doesn't seem to work
|
|
#func _on_Hurtbox_Component_body_entered(body):
|
|
# print(body.name, "hit", owner.name)
|
|
# if owner.has_method("gotcha"):
|
|
# print(body.name, " you can do it.", owner.name)
|
|
|
|
|
|
# well this one works.
|
|
#func _on_Hurtbox_Component_area_shape_entered(area_rid, area, area_shape_index, local_shape_index):
|
|
# #print(area.get_parent().name, "hit", owner.name)
|
|
## if area.get_parent().has_method("gotcha"):
|
|
# print(area.get_parent().name, " you can do it.", owner.name)
|
|
#
|
|
# if owner.has_method("_on_Hurtbox_area_entered"):
|
|
# owner.call("_on_Hurtbox_area_entered")
|
|
# print(area.get_parent().name, " just hit me: ", owner.name)
|