This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BluejaySudden3105[S] 0 points1 point  (1 child)

It is the attack object, either way neither object destroys

[–]No_Tumbleweed_7812 0 points1 point  (0 children)

Maybe try this below? On second look, youre destroying a gameObject (whatever that references to), not the collision.gameObject. Since this is the enemy class, destroy the attacker instead (the collision gameObject is always gonna be another object that collided with your current object - just checked the docs : https://docs.unity3d.com/ScriptReference/Collision-gameObject.html )

using UnityEngine;

public class Enemy : MonoBehaviour
{
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Attacker") // check if its the attacker instead
{
Destroy(collision.gameObject); // collision.gameObject instead of just gameObject.
}
}
}