Hello, I am a beginner to Unity and C#. I have an enemy and the object the enemy is trying to attack. I have tried to make it so when the enemy collides with this object, it will get destroyed. I have gotten this code from another, more older, thread(which I have modified). If anyone could help, it would be greatly appreciated!
using System.Collections;
using UnityEngine;
public class DestroyOnCollision : MonoBehaviour
{
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Enemy")
{
Debug.Log("collision detected!");
Destroy(gameObject);
}
}
}
Nevermind, I have solved the issue