Hi
I am new to C# and Unity. I have searched the web and I am finding it hard to implement a game mechanic. I am working on a mechanic which takes away health to perform a special move. This special move will destroy all enemies with a certain tag, however I am not sure how to do this.
I have came across FindGameObjectsWithTag but as I have said I am not sure how to implement this. I have read the Unity script reference and not sure how to take whats there and put it in my code. If it helps heres the code I have at the moment.
if (Input.GetKeyDown (KeyCode.Keypad8) & shieldHealth > 50)
{
shieldHealth -=50;
print ("I have enough health");
}
Any help is greatly appreciated. Thanks in advance.
this can help you destroy all object with same tag on key press you just need to set a partical affect to go off at the same time to look like an attack
var Enemies: GameObject;//declares an array of GameObjects
//to be filled later
function Start()
{
Enemies = GameObject.FindGameObjectsWithTag("Enemy");
//fill the Enemies array with actual enemy GameObjects
//"Enemy" is the tag your enemies have
}
function Update()
{
if (Input.GetKeyDown (KeyCode.Keypad8) & shieldHealth > 50)
{
shieldHealth -=50;
for(var EnemyCurrent in Enemies)
//iterates (loops) through your array, EnemyCurrent is a temporary
//variable given to the current array entry each loop start
{
Destroy (EnemyCurrent);//Destroys the current enemy object
}
print ("I have enough health");
}
}