Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Inan-Evin · Mar 14, 2012 at 02:13 PM · aienemyreloadreloading

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 :).

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Berenger · Mar 14, 2012 at 02:37 PM 2
Share

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 ?

avatar image Inan-Evin · Mar 14, 2012 at 05:24 PM 0
Share

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 ?

avatar image Owen-Reynolds · Mar 15, 2012 at 03:13 AM 1
Share

Are you sure that the "takeCover" script doesn't have static isReloading: bool;? That would perfectly explain your issue.

avatar image Inan-Evin · Mar 19, 2012 at 05:44 PM 0
Share

well, thanks I didn't notice that, thank you both for answering :).

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges