Godot Version
<stable4.2>
Question
<Hi. Im making hitbox and hurtbox classes, and getting Unreachable code (statement after return) in function "get_damage()".
error inside hitbox class script. I would appreciate if you could teach me how to solve problem. also, i am still not sure how exactly to use hitbox hurtbox classes. Since hitbox class script will be shared among all attached nodes, how would I have different damage value for different enemies?
Hitbox script:
@icon("res://entities/node/HitBox.svg")
class_name HitBox
extends Area2D
@export var damage := 10
func _ready():
pass # Replace with function body.
func get_damage() -> int:
return damage + randi() % 7 - 3
print("damage")
Hurtbox Script:
@icon("res://entities/node/HurtBox.svg")
class_name HurtBox
extends Area2D
func _ready() -> void:
connect("area_entered", _on_area_entered)
func _on_area_entered(hitbox: HitBox) -> void:
if owner.has_method("take_damage"):
owner.take_damage(hitbox.get_damage())
if owner.has_method("knock_back"):
owner.knock_back()