How can I set a unique int to every GameObject in my array?
public GameObject[] targets;
private void Update()
{
targets = GameObject.FindGameObjectsWithTag("Enemy");
}
How can I set a unique int to every GameObject in my array?
public GameObject[] targets;
private void Update()
{
targets = GameObject.FindGameObjectsWithTag("Enemy");
}
Just assign the index in the array. Guaranteed to be unique.
They already have a Unique ID! GetInstanceID:
private void Update()
{
targets = GameObject.FindGameObjectsWithTag("Enemy");
foreach(var t in targets)
{
Debug.Log(t.GetInstanceID());
}
}
That’s guaranteed to be the same thing no matter where you look at the object from.
Thanks this worked just fine ![]()
Thank you
I used the array index as @Kiwasi suggested! ![]()