Enemy Attack Order List.

I’ve programmed a Melee AI system where the enemy moves towards the target and attacks every so often. But I want to make it so when there is more than one enemy they take turns attacking instead of both attacking at the same time. So I figured I could use a list and a collider as a child of the player to add them into a Battlemanager script. Though I am completely unsure on how to add them to the list on entering the trigger, and then make them to only attack if they are position 0 in the list and once they have attacked to be put to the back of the list or if they are out of range / leave the trigger to be removed from the list.

Any links to where I should look would be much appreciated, or even some code samples would be fantastic (I am working in C#)

Unsure on where to start so no code samples :confused: My knowledge of lists isn’t that strong.

To use Lists in Unity, you will need to add to the top of your file:

using System.Collections.Generic;

Learning how to use in Unity:

http://unity3d.com/learn/tutorials/modules/intermediate/scripting/lists-and-dictionaries

For information on data structures, see MSDN (Microsoft Developer Network)

For east to understand implementation, also try

There are some basic information that you should know about lists to get you started.

One you need to add ‘using System.Collections.Generic;’ to the top of your script.

Here goes:

A list is a lot like an array except that one can dynamically change its contents during gameplay.
To start a list ‘List players = new List();’

Since GameObject.FindWithTags returns an Array not a list. You will have to create an array and transfer the data over like this:

'GameObject pArray = GameObject.FindWithTags(“Players”);
for(int i = 0; i < pArray.Length; i++)
{
players.Add(pArray*);*
}
’ This shows another of a lists functions, Add(). If you want to access a lists objects simply ‘player[0].name’ sort of like an array.
Unlike an array when finding the length of the list use List.Count NOT List.Length.
Hope this is enough information. And of course richyrich posted a couple docs for reference.
Good Luck!