How do I make my enemies delete their game object (themselves) from the scene. The code I have so far is:
using UnityEngine;
public class EnemyDiesOnImpact : MonoBehaviour
{
[SerializeField] private LayerMask whatDestroysEnemy;
private Rigidbody2D rb2d;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if ((whatDestroysEnemy.value & (1 << collision.gameObject.layer)) > 0)
{
Destroy(gameObject);
}
}
}