- Edited
In my Player class I want to respond to the "body_entered" signal from an Area2D when Player collides with Class Enemy. Then I want to reference a property in the Enemy body we collided with. I cannot figure out how to recast the BodyEnterered signal.
hurtBox.BodyEntered += OnHurtBoxBodyEntered; // In _Ready()
private void OnHurtBoxBodyEntered(Node2D body) {
Enemy e = (Enemy) body;
if(body.IsInGroup("Enemy")) {
GD.Print("Player Body Entered by " + body.Name);
HealthManager.DecreaseHealth(e.DamageAmount);
HealthManager.DecreaseHealth(body.DamageAmount);
}
The body.DamageAmount
throws VSCode/compiler error:
'Node2D' does not contain a definition for 'DamageAmount' and no accessible extension method 'DamageAmount' accepting a first argument of type 'Node2D' could be found (are you missing a using directive or an assembly reference?)'
I tried (Enemy body) in the function definition, but it didn't like that either. What do I have to recast so I can use the body.DamageAmount
reference?