Hello,
I have set up a simple script that should destroy a game object, if it is a certain type of prefab.
[SerializeField] private GameObject rocketToKill;
private void OnTriggerEnter2D(Collider2D collision)
{
print("collided with " + collision.gameObject.name);
if (collision.gameObject.name == "playerRocket(Clone)")
{
print("rocket destroyed");
}
}
As you can see, I have set up a field in the inspector to hold a game object type, namely the only object that should be destroyed when it enters the collider. Right now I check for that by comparing the name, but I’d rather check against the type directly. Is that possible? I’ve already tried things like:
if (collision.gameObject == rocketToKill)
but that does not work.
I could tag the game object in question, but I reaaaally want to check against a pre defined prefab.