- Home /
Enemy AI Reloading Problem, they reload with queue
Hello everyone, I have an AI code and it works perfect with only 1 enemy in the scene. But when I put 2 enemies, things get complited. My problem is , let me explain like that :
Enemy 1 Enemy 2
we have these two enemies in the scene, when both of their mags are finished, they are supposed to start reloading. But for example Enemy1's ammo finished first, so Enemy1 starts reloading, while Enemy2 waits for Enemy1 to finish it's reload, after 1 is finished, Enemy2 starts reloading, in the meanwhile, Enemy1 waits for Enemy2 to finish it's reload instead of firing or taking cover. It's like they are doing their reloads with a queue. So here is my reload code :
function Reload(){
var a =gameObject.GetComponent(EnemyAI);
a.shoot=false; // disable shooting
// I did it like this to change the variable ONLY for the gameObject which does the Reload, but didn't work anyways.
var b = gameObject.GetComponent(takeCover);
b.isReloading=true; // so there is a isReloading value in my cover code, if it's true enemy will not try to take cover, it'll just stand where it is.
gameObject.animation.wrapMode=WrapMode.Once;
gameObject.animation.CrossFade("reload"); // reload animation
Instantiate(reloadSound,transform.position,Quaternion.identity); // reload sound
yield WaitForSeconds(3.5); // wait for 3.5 secs to finish it's reload
gameObject.GetComponent(EnemyAI).ammo=30; // refresh bullet
var c= gameObject.GetComponent(takeCover);
c.isReloading=false; // disable isreloading, so it can shoot again or take cover.
}
so what can be the problem, they wait for each other to finish reloading before each of them do it's own reloading, if you guys need any other information to understand the codes, please let me know , thanks :).
There shouldn't be any relation between the two AI, as if they where in two separate scenes. Do they share a component, or static vars ?
no they just have the same EnemyAI code and takeCover codes also the animations but it's the same enemy model it should be like this. What else should I look for in common ?
Are you sure that the "takeCover" script doesn't have static isReloading: bool;
? That would perfectly explain your issue.
well, thanks I didn't notice that, thank you both for answering :).
Your answer
Follow this Question
Related Questions
Saving layout and enemy stats with Binary Formatter 0 Answers
How to reach multiple GameObjects' value , enemy AI 1 Answer
Enemy Ragdoll help 1 Answer
Enemy AI help. 0 Answers
Why doesn't this AI script work? c# 1 Answer