I am making a trigger zone and the only problem is that I don’t know how to tell it to destroy the player.
This is my script
public class DeadScript : MonoBehaviour { private void OnTriggerEnter(Collider coll) { if (coll.CompareTag ("Player")) { Destroy(gameObject); } } }
The sprite that I am trying to destroy is a cube that I renamed to Player when I put it into the game. When I tried the script above and it kept coming up with an error so I changed Player to gameObject and when the player touched the zone they didn’t disappear, this script is attached to the zone which is just a transparent cube without a collider by the way.
When you are using “gameObjet” in a script, it is refering to the GameObject that the script is attached to. In your case, the line Destroy(gameObject)
will destroy the object with the trigger collider, since this is the one that the script is attached to.
If you want to destroy the object that is colliding with the trigger collider -aka the player in your case- you have to do Destroy(coll.gameObject)