Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | maimon |
I have 2 nodes in the enemy node the first is HurtBox which has a script:
if owner.has_node("Health"):
var health : Health
health.damege(10)
and the second is Health which has a script:
extends Node2D
class_name Health
.
func damege(amount : int):
health -= amount
if health <= 0:
get_parent().queue_free()
I don’t know why I can’t use the Damege function
note: when I ctrl+click on it, it takes me to damage func in the Health script
my godot version 3.5.2
It looks like you declare the health
variable, but don’t initialize it to any value in your Hurtbox script. var health
says make me a new variable and : Health
tells Godot that the variable health
you are making has a type of Health
(matches the Health
class). This means Godot will know that health
should have a damege function and will find it when you ctrl + click on it. But you are missing the part where you initialize your variable health
to something. That’d look something like var health : Health = owner.get_node('Health')
Tom Mertz | 2023-05-22 22:12