Destroy player when it collidese with something

Just trying to destroy my player when it collides with a obstacle. /: This is what I got.

using System.Collections;
using UnityEngine;

public class DestroyPlayer : MonoBehaviour
    void OnCollisionEnter(Collision col)

        if ( == "Obstacle")


In case your script’s attached to player, you need to destroy this.gameObject
In case it’s attached to the obstacle, you need to check the name of the collision gameObject you want to destroy, and then destroy col.gameObject

First of all, I am assuming this script is on your obstacle. You are checking for a collision on your obstacle. You are then seeing if that collision is the obstacle (this will probably never be true). Then you are destroying your obstacle if it is somehow true (like maybe another obstacle hit this obstacle, in which case they would probably destroy each other?).

Anyways, you need to check if col.gameObject is the player. Maybe do this using a tag instead. Tag your player as “Player” and try something like:

if(col.gameObject.CompareTag("Player")) //If a player hits the collider of this obstacle

Hope this helps. Good luck! :slight_smile:

i tried this…

all i get is the folowing…

Assets\Scripts\DeathZone.cs(7,13): error CS0103: The name ‘col’ does not exist in the current contextany ideas please?