'Node2D' does not contain a definition for 'CollectCoin'

Thats not how things are done in a typed language such as C#.
body is a Node2D and Node2D has no method called CollectCoin. That is not dynamically discovered at runtime, but already certain when you try to compile the project, which is why it doesn’t compile. Only your Player class (whatever its named) has such a method. You seem to attempt ducktyping with HasMethod like you can do in GDScript, but that’s not the C# way. Instead, check if body is of your Player type with
if (body is Player)
{
body.CollectCoin();
QueueFree();
}

That should automatically cast body inside the if statement to Player, so you can call the method.

1 Like