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 VinnyG · Mar 01, 2012 at 09:31 PM · c#animationtargeting

multiple objects not behaving independently

I'm using 2d animations to represent my ally units attacking enemies. The problem is when there is more than one of the same unit spawned into the scene their animation sometimes do not behave independently. I have it set so the unit starts moving once its enemy is dead and its animation is done. However, other units of the same kind will not move until all animations are finished. So even though one ally may have started and finished his attack before another of the same kind he waits util the other is finshed before moving on. Here is the relevant code:

void TargetSearch(){

     GameObject on = GameObject.FindGameObjectWithTag("enemytag");
     
     if(on != null ){            
         
     target= on.transform;
     
         
     xa = transform.position.x;
     c = target.position.x;
     
     //stop and shoot when within shooting distance along x axis
     if(c<=xa+dist & sec == false ){//sec is for the gap in bullet firing
     
         currentSpeed = 0;
         if(currentSpeed == 0){AllyAnim.PlayAnim(1);audio.PlayOneShot(Uzi);}//else{AllyAnim.PlayAnim(0);}
         sec = true;
         StartCoroutine(WaitB());
                 }
         
     }

IEnumerator WaitB(){

     yield return new WaitForSeconds(1.25f);
     if(c<=xa+dist){EnemyScript.Health--;}
     sec = false;
     
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Mar 01, 2012 at 09:48 PM

Seems like maybe all allys are finding the same enemy and waiting until it's dead? Is there more than one enemy at a time is really my question. How are you getting EnemyScript? FindWithTag will get the first one it finds. If you have more than one enemy, you should assign each enemy to specific allys (or vice-versa) so each ally knows who it's attacking and when it's dead.

Comment
Add comment · Show 2 · Share
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 VinnyG · Mar 02, 2012 at 05:57 PM 0
Share

Hi

There are multiple enemies spawned at the same time. There doesn't seem to be a problem picking up new enemies once the allies start moving again. The only delay is when one of the allies hasn't finished the attack animation even after the target is dead. $$anonymous$$y target search in essence is picking up any tagged enemies in range and performs an attack until the enemy is dead. There is no problems if I have multiple enemies or even multiple allies of different types its just when multiple versions of the same unit are spawned.

avatar image VinnyG · Mar 02, 2012 at 08:30 PM 0
Share

Sorry to waste your time I just realised I had another coroutine that interfered with the one I had set up to wait for the attack animation thanks anyway :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Tips on managing animation states 2 Answers

How can i make this animation play only once? C# 1 Answer

What would be the best way to do something based on the animation state of the character? 0 Answers


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