I've asked this on the forum already and getting some help but it's all about arrays and i feel that there must be a simpler way of doing this instead of reconstructing my AI using Arrays which is daunting to me.
What I'm trying to do is be able to have any number of attacking characters in my game (what I call baddies) using AI. Now the AI that I've been implementing and adjusting in my own way comes from Unity. However the setup implies that you only encounter one baddie at a time, thus there is no conflict. When you have multiple baddies then I have been forced to make multiple AI scripts, but as my numbers of baddies goes up for each scene it gets harder to justify copying my AI script, and my Attack script which are named AI-n1, AI-n2 along those lines so that they can be assigned to each character, baddie1 baddie2 etc..
What I need . I attach my Baddie_Collision script to the badguy and I assign a number in the inspector once attached. The AI and Attack scripts look to this number to make sure a hit doesn't affect a different bad guy or that I can get them to attack at different speeds. What I want is to just have one script elegantly track them by just identifying the number I'm accessing.
In Baddie_Collision I set the number:
var baddieNum = 1; //always starts here but each baddie goes up one digit
Then in the same script I do a check for collisions to the projectile being thrown at them...
if (baddieNum == 1) { AI2n1.getHit1 ++ ; }
I cycle through for each number of baddies I have.
What I want to do above is this within the triggerEnter assuming the baddie has been hit,
AI2_ALL.getHit{baddieNum} ++;
I am using the squiggle brackets because I don't know what they mean to unity. I've used things like this before or variants, AI2_ALL.getHit${baddieNum}. An example that comes to mind is scripting in TCL/TK I think Perl has a control like this as well.
The above assumes that we know the number bad guy, and that Unity is smart enough to parse the variable above as AI2_ALL.getHit1 (or whatever baddieNum happens to be set to in the inspector on that character).
Now, I've written this kind of thing a million times before, but not in Unity scripting language so I don't know how to parse this above with the correct syntax.
Setting up Arrays does not sound like the direction I want to go in because I have other values I want to also parse this way too such as isAttacking{baddieNum} and it would mean gutting my code in associated scripts.
I believe that most languages have a certain syntax to make the above read correctly so that it sees baddNum1 as the variable. Not all maybe, but many.
I hope this explains what I'm trying to do accurately and that someone may shed some light on this because I don't know where to look for this in the reference as everyone does this differently.