Error I'm unable to fix

Hi again,

So I’m working on a very simple script, I have these 2 following classes which I will call for player death

public class Player : MonoBehaviour
{
    [SerializeField] private float deathHeight = -20f;

    // Update is called once per frame
    void Update()
    {
       
    }

    private void PlayerFall()
    {
        if(transform.position.y < deathHeight)
        {
            GameMaster.KillPlayer(this);
        }
    }
}

And

public class GameMaster : MonoBehaviour
{
    public static void KillPlayer (Player player)
    {
        Destroy (player.gameObject);
    }
}

I get this code indicated on the “this” argument in the PlayerFall() function

“Argument 1: cannot convert from ‘Player [Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]’ to ‘Player [Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]’ [Assembly-CSharp-Editor]”

What does this mean?

What I did to fix it was I changed the (Player player) argument to KillPlayer (GameObject player) and it worked.

I’m just wondering why the previous one didn’t work?

Previous one didn’t work becouse “this” refers to the script itself not the gameObject it is attached to and Destroy() method does’t work for components (the script is a component). It works for gameObjects.

Aha, cool. Thanks!