Unity not recognising Destroy()

Hello, Unity is giving me these two errors and not recognising Destroy()

error CS1503: Argument #1' cannot convert string’ expression to type UnityEngine.Object' error CS1502: The best overloaded method match for UnityEngine.Object.Destroy(UnityEngine.Object)’ has some invalid arguments

Here is my code:

using UnityEngine;
using System.Collections;

public class ContactWithPlayerKill : MonoBehaviour 
{
	void OnCollisionEnter (Collision col)
	{
		if (col.gameObject.tag == "Player")
		{
			KillPlayer();
		}
	}

	void KillPlayer ()
	{
		Destroy("Player");
	}

}

“Player” is simply a string, not an object reference.
Try doing this instead:

public class ContactWithPlayerKill : MonoBehaviour 
{
    void OnCollisionEnter (Collision col)
    {
       if (col.gameObject.tag == "Player")
       {
         KillPlayer( col.gameObject );
       }
    }
 
    void KillPlayer ( GameObject DestroyMe )
    {
       Destroy( DestroyMe  );
    }
}

Try this script. Same as your script with some edits :slight_smile:

using UnityEngine;
using System.Collections;

public class ContactWithPlayerKill : MonoBehaviour 
{
    void OnCollisionEnter (Collision col)
    {
       if (col.gameObject.tag == "Player")
       {
         KillPlayer(col.gameObject);
       }
    }
 
    void KillPlayer (GameObject pPlayer)
    {
       Destroy(pPlayer);
    }
 
}