Distinguishing between same named objects. (instantiated)

I am totally new at Unity and I was hoping someone could help me with this problem. I have been trying to create individual health bars for enemies, but the problem is they are instantiated (spawned) and thus all go by the name drone(clone). Their children have all the same names too so I don’t know how to get the health bar to communicate with the drone its attached to without calling all the health bars/drones.

I made this one attempt of altering a variable on each drone thats instantiated that way each drone has a variabel that is different than the last, but by doing this i have to right a huge if statement clause to count for each different variable drone multiplied by the amount of health steps i use.

if there was someway to send messages with a variable or change the name of an object, those seem like they would work at fixing the problem.

thanks.

Maybe, you can add a script component to drone prefab which contains some health variances. Then instantiate the drone under a parent object, named e.g Drones. Call this function: GameObject.Find(“Drones”). GetComponentsInChildren(); you will get an array of Script component, use foreach clause to do something.

Create a reference to the instantiated object and then use the reference to change it’s name property.
var myObject = instantiate(gameObject, transform.position, Quaternion.identity);
myObject.name = “somename”;

You can use a tag, just before the drone is instantiated, setup a few conditional statements that tag the newly instantiated object. Then on the drone’s script have it read its own name and assign the correct amount of health.

(ie)
if(droneType==0) { Obj.tag = “Drone_1A”; }
else if(droneType==2) { Obj.tag = “Drone_3A”; }
else if(droneType==4) { Obj.tag = “Drone_5A”; }
}
Obj = Instantiate(Obj, transform.position, transform.rotation);

(ie)After Instantiated
if(gameObject.tag==Drone_1A) {//One time call from a script on the Drone.
gameObject.tag = Drone;
healthPoints = 90;
}

Also you can use a trigger, OnTriggerExit set the health points to the value you control.

Thanks, i managed to name each instantiated enemy differently now (I used a tagging system along with a name changing one) and unity has no problem identifying the different enemies/health bars. The problem now is that i cannot change the color of the health bars. The health bar is a child of the drone, but every time i try renderer.material.color = Color.green;
I get the error that the renderer does not exist. I imported the object through fbx and I believe I found the renderer on the mesh of the object, but I do not know how to access it. Any help would be appreciated

Nvm, thanks anyways. By attaching the health bar script to the healthbar mesh with the renderer, I solved the problem. I feel a bit stupid though since it was so easy.