using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeathTraps : MonoBehaviour {
public Transform player;
void OnCollisionEnter(Collision collision)
{
if( collision.gameObject.tag == "Player" )
{
Destroy(collision.gameObject);
}
}
}
Your trap should have a trigger collider on it. Your player probably should just have a normal non trigger collider. One of them needs a rigidbody (likely player)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeathTraps : MonoBehaviour {
public Transform player;
void OnTriggerEnter(Collider other)
{
if( GetComponent<Collider>().gameObject.tag == "Player" )
{
Destroy(other.gameObject);
}
}
}
sorry just changed the code now but yeah player moves through the trap
it’s 2D but i’m using 3D colliders as they seem to work better for this type of game and i have tried the 2D colliders and not entirely sure XD thats my error as i forgot what i needed to put there. Also tried the rigidbody thing didn’t work
You might have missed where I mention the GetComponent thing as I added it after.
I’m unsure how well the 3D stuff works with 2D, since there is also a 2D rigidbody. That may be why it doesn’t work even when everything is correct, but not sure.