why oncollisionenter2d doesn't work for me?

Viewed 12

I wrote a script for my prefabs to destroy when they touch each other, but oncollision2d doesn't work. Can anyone help me?

this in my player inspector

    private void Start()
{
    _player = GameObject.Find("Ship").GetComponent<ShipController>();
}

private void OnCollisionEnter2D(Collision2D colisn)
{
    if(colisn.gameObject.tag == "Player")
    {
        SpawnExplosion(transform);
        _player.Hurt();

    }

    if(colisn.gameObject.tag == "Meteors")
    {
        SpawnExplosion(colisn.gameObject.transform);
        SpawnExplosion(transform);
        Destroy(colisn.gameObject);
    }
}

private void OnTriggerEnter2D(Collider2D colisn)
{
    if(colisn.gameObject.tag == "Meteors")
    {
        Destroy(gameObject);
    
        Destroy(colisn.gameObject);
        
        SpawnExplosion(colisn.gameObject.transform);
    }


}

private void SpawnExplosion(Transform transform)
{
    GameObject exploClone = Instantiate
        (_explosionPrefab, transform.position, transform.rotation);
}

my objects inspector is here

0 Answers
Related