S
S
Shallmick2021-10-09 17:56:17
Unity
Shallmick, 2021-10-09 17:56:17

How to take into account the collision with the player?

I want it to delete my player only if it collides with the player itself, and ignore the rest of the colliders

private GameObject targett;
    
    
    void Start()
    {
        targett = GameObject.FindWithTag("Player");
        
    }

    
    void Update()
    {
        
    }

    

    private void OnTriggerEnter2D(Collider2D collision)
    {
        Destroy(targett);
    }


}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Loli E1ON, 2021-10-09
@Alexander_020

You can check the tag...

if (collision.gameObject.CompareTag("Player"))
{
    Destroy(collision.gameObject);
}

Or compare things...
if (GameObject.ReferenceEquals(collision.gameObject, targett))
{
    Destroy(targett);
}

Or set up layers so that the collision you need collides only with the player's collision...
https://docs.unity3d.com/Manual/LayerBasedCollisio...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question