I am trying to get my AI to prioritize multiple enemies based on many different factors.
Right now I have a pretty basic setup. When the AI see’s an enemy it adds it to a generic list “enemyList” of type gameobject.
I have a coroutine that iterates through each element of “enemyList” with a for statement.
I check each element of “enemyList” for a bunch of stuff like distance, health, weapon type being carried, etc. Based on those values, I generate a priority value which I store in a new generic list “priorityLevel” of type float.
This works for now but I see this work flow getting very messy quickly. And if I want to store more info. about each element of “enemyList”, I am making more lists. And I don’t want to add a new list for every piece of info. I gather when I iterate through each element of “enemyList”
Is there an easier way to store all the info about each element of “enemyList” in 1 place? So I can easily look up and compare info’s about each element of “enemyList”.
From my research dictionaries and list are the way to go but I am really struggling with the syntax. I think I am suppose to create a separate class for the multiple variables I want to store but am struggling with syntax.
Any help appreciated, thanks.
IEnumerator Priority()
{
while (enemyList.Count > 0)
{
for (int i = 0; i < enemyList.Count; i++)
{
priorityLevel.Add(0f);
distance = Vector3.Distance(transform.position, enemyList*.transform.position);*
_ priorityLevel += distance;_
_ rifleCheck = enemyList*.GetComponent<Animator().GetBool(“RifleState”);
if (rifleCheck == true)
{
priorityLevel += 10.0f;
}
}*_
* yield return new WaitForSeconds(2f);*
* }*
* }*