- Home /
Instantiation array of enemies, c# ?
How exactly would I instantiate a player targeting enemies from an array of enemies in C# to attack them and decrease their health?
This is a bit of a strange question.
Is your array of enemies already instantiated ?
How is the player selecting an enemy to attack ?
Answer by MochaMessiah · Sep 11, 2012 at 10:45 AM
I honestly don't know if they are or aren't. Right now in my player attack script I have code that looks like this.`public GameObject target;`
This allows me to drag an enemy onto here in the inspector window and from my knowledge that is how I can attack and hurt the enemy. I also have code stating if the player is ye high and the corresponding button is pressed then adjust the enemy's health by -10.
Now if I have 5 enemies how do I hurt them all separately? Do I instantiate them?
I honestly have no idea.
First id add this conversation either to your original post or as comments not as answers.
If your enemies already exist you need to build a list yourself.
You can find other game objects in Uity really easily , either by name or by Tag.
Have a look at this
http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
Try this example.
Thanks and yeah sorry, I am still getting use to this :P
Your answer
![](https://koobas.hobune.stream/wayback/20220613080911im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Burgzergarcade VitalBar.cs Problem 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Trying to make gameObjects the target on right click 2 Answers
How can i make a ray cast take health from enemies 2 Answers