Hello, sorry for this beginner question but I couldn’t find anything similar in Google (trust me I tried),
Basically I have a situation in which I have multiple objects being spawned at the same time, each 2 of those objects have the same name and tag and if you drag one of the those objects on top of the other both will get destroyed.
The issue I’m having is that I have a huge number of objects and I don’t think that I should create a different script for each of them with a different tag (the only way I know how to trigger this would be through a different CompareTag(“Name”) script for each type of object) but I’m pretty sure this would be wrong.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyCheck : MonoBehaviour
{
void OnTriggerEnter(Collider GameObject)
{
Debug.Log(gameObject.name);
Debug.Log(gameObject.tag);
if (GameObject.CompareTag("SameName"))
{
Destroy(GameObject.gameObject);
Destroy(this);
}
else
{ }
}
}
I want to get rid of if (GameObject.CompareTag("SameName"))
but I don’t know how I would be able to set it up,
I think the easiest way would be to get the name of the Object or Tag in the start of the script and by some way put it for comparison,
Sorry for my weird explanation but those were the easiest words I found,
Thank you.