- Home /
Throw something at a prefab
Alright so right now I have a bunch of enemies spawn as prefabs. Each one has a empty gameobject attached to them and I want the player to be able to throw a block at the enemy targets empty gameobject location. What I want to happen is have it go to the nearest facing enemies gameobject but am unsure how to do this for prefabs? If it was an existing enemy in the scene it's a lot easier to do this so I am lost on how to do this for a prefab.
Answer by Berenger · Feb 17, 2012 at 12:01 AM
You're unclear with the notion of prefab. You are actually talking about instantiations of a prefab.
As for your question, I suggest you use a specific tag for those targets, Find() them using that tag then search the closest one and finally fire.
So I would just check the distance each enemy is from the player and then select one and use it's tag ?
Almost, bu wrong order :p
FindObjectsWithTag
Use sqr$$anonymous$$agnitude to find the closest
AddForce