简体   繁体   中英

Unity2D How to ignore collisions with specific objects?

I am using an animated sprite to collide and delete an enemy sprite. The enemy sprite disappears when it hits my floor (sprite) also. (All have rigidbody2D). How do I get the enemy sprite to ignore the floor and everything else except the animated sprite?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Collision : MonoBehaviour
{
    void Start()
    {

    }

    void Update()
    {

    }

    void OnCollisionEnter2D()
    {
        if (gameObject.tag.Equals("Enemy"))
        {
            Destroy(gameObject); 
        }
    }
}

Go to Edit > Project Settings > Physics (or Physics2D ) and edit the Layer Collision Matrix:

层碰撞矩阵

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM