I have two scenes: Player and Coin. Both of these scenes are inherited from Area2D. Code of these scenes:
Player:
public void OnAreaEntered(Area2D area)
{
if (area.IsInGroup("coins"))
{
area.Pickup();
}
}
Coin:
public void Pickup()
{
QueueFree();
}
OnAreaEntered checks if the player has touched an Area2D object, and if he has touched a Coin, on the coin touched by the player, the Pickup() method is launched. But it doesn't work. I can't solve this problem:
Well, I was able to solve this problem by simply changing the data type "Area2D" to the data type "Coin" in the arguments of the OnAreaEntered method. But there is a problem: the OnAreaEntered method will recieve not only data with the data type "Сoin". What I should do?
I know that the OnAreaEntered method really recieves coin when the player touches it:
public void OnAreaEntered(Area2D area) {
GD.Print(area.HasMethod("Pickup")); // TRUE
}