Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Ambassador_of_Infinity · Feb 18, 2019 at 08:45 AM · bugcoroutineupdateweapon system

Weapons that used to work got broken after update - has StopAllCoroutines() stopped working?

The title says it all - Weapons I have created were working fine until I've updated Unity to 2018.3.6f1 (or at least this is the shortcut name) - now their bullets are doubled. Scripts haven't been changed. Edit : Is seems like that disabling causes the problem - when spaceship was disabled, it's weapons weren't firing and were resetted after that. I use StopAllCoroutines() to reset weapon, so maybe this stopped working after the update or something like that. I'lll try to rewrite the script, but if this is true, the problem is far greater than doubled bullets...

Sorry for all mistakes (if there are any. Probably yes), hard-to-understand scripts or anything that makes my problem harder to understand and solve. I hope one of you all wants to help me, even though I don't really know how you can do this...

Function for being disabled :

 public IEnumerator Disabled(float t)
     {
         foreach (Image img in GameObject.Find("ShipActivatable").GetComponentsInChildren<Image>()) //Maybe ship was clicked
         {
             img.enabled = false;
         }
         foreach (SpriteRenderer sprite in GameObject.Find("ObjectMarker").GetComponentsInChildren<SpriteRenderer>())
         {
             sprite.enabled = false;
         }
         GetComponentInChildren<KeepRotation>().GetComponentInChildren<SpriteRenderer>().enabled = false;
         GetComponent<ClickDetector>().enabled = false;
         GetComponent<ClickDetector>().clicked = false;
         GetComponent<ClickDetector>().clickable = false;
         ShipWeaponPointing[] weapons = GetComponentsInChildren<ShipWeaponPointing>(); //Block weapons
         foreach (ShipWeaponPointing weapon in weapons)
         {
             weapon.GetComponent<WeaponWorking>().StopAllCoroutines();
         }
         GetComponent<ShipInfo>().disabled = true;
         GameObject mothership = GameObject.FindGameObjectWithTag("Player");
         mothership.GetComponentInParent<FlagshipScript>().canMove = true; //Make player ship controllable if it wasn't
         time += t;
         for (int i = 0; i < time*10; i++) //Wait
         {
             yield return new WaitForSeconds(0.1F);
         }
         time = 0;
         GetComponent<SpecialScript>().RestartWeapons(); //Reset weapons
         GetComponent<ShipInfo>().disabled = false; //Make ship interactable again
         GetComponent<ClickDetector>().enabled = true;
         GetComponent<ClickDetector>().clickable = true;
     }

Function for resetting weapons :

     public void RestartWeapons()
     {
         for (int i = 0; i < 8; i++) //For every weapon
         {
             GameObject go = null;
             int t = 99;
             if (i == 0) //Finding tech
             {
                 t = GetComponent<ShipInfo>().W1;
             }
             else if (i == 1)
             {
                 t = GetComponent<ShipInfo>().W2;
             }
             else if (i == 3)
             {
                 t = GetComponent<ShipInfo>().W4;
             }
             else if (i == 2)
             {
                 t = GetComponent<ShipInfo>().W3;
             }
             else if (i == 4)
             {
                 t = GetComponent<ShipInfo>().W5;
             }
             else if (i == 5)
             {
                 t = GetComponent<ShipInfo>().W6;
             }
             else if (i == 6)
             {
                 t = GetComponent<ShipInfo>().W7;
             }
             else if (i == 7)
             {
                 t = GetComponent<ShipInfo>().W8;
             }
             foreach (WeaponSetting ws in GetComponentsInChildren<WeaponSetting>()) //Finding weapon to re-set
             {
                 if (ws.pos == i)
                 {
                     go = ws.gameObject;
                 }
             }
             if (go != null) //Resetting specified weapon
             {
                 WeaponWorking ww = go.GetComponent<WeaponWorking>();
                 ww.StopAllCoroutines(); //Stopping weapon if it wan't stopped previously
                 if ((0 <= t && t <= 3) || t == 31 || t == 40 || t == 49) //Gun
                 {
                     ww.StartGun(ww.mainParameters[0], ww.mainParameters[1], ww.mainParameters[3], ww.mainParameters[4], (int)ww.mainParameters[5], (int)ww.mainParameters[6], (int)ww.mainParameters[7]);
                 }
                 else if (t == 9 || t == 32 || t == 42) //Laser
                 {
                     ww.StartLaser(ww.mainParameters[2], ww.mainParameters[3], (int)ww.mainParameters[5], (int)ww.mainParameters[6], (int)ww.mainParameters[7]);
                 }
                 else if ((17 <= t && t <= 20) || t == 26 || t == 33 || t == 51) //Missile or Torpedo
                 {
                     if (ww.mainParameters[10] == 1)
                     {
                         ww.StartMissile(ww.mainParameters[0], ww.mainParameters[1], ww.mainParameters[3], ww.mainParameters[4], ww.mainParameters[9], ww.mainParameters[8], true, (int)ww.mainParameters[5], (int)ww.mainParameters[6], (int)ww.mainParameters[7]);
                     }
                     else
                     {
                         ww.StartMissile(ww.mainParameters[0], ww.mainParameters[1], ww.mainParameters[3], ww.mainParameters[4], ww.mainParameters[9], ww.mainParameters[8], false, (int)ww.mainParameters[5], (int)ww.mainParameters[6], (int)ww.mainParameters[7]);
                     }
                 }
                 else if (t == 25 || t == 41) //Thrower
                 {
                     ww.StartThrower(ww.mainParameters[2], ww.mainParameters[1], ww.mainParameters[3], ww.mainParameters[4], (int)ww.mainParameters[5], (int)ww.mainParameters[7]);
                 }
                 else if (t == 10 || t == 11 || t == 43 || t == 50) //Net or Harpoon
                 {
                     if (ww.mainParameters[10] == 1)
                     {
                         ww.StartHarpoon(ww.mainParameters[0], ww.mainParameters[1], ww.mainParameters[3], ww.mainParameters[4], ww.mainParameters[9], true, (int)ww.mainParameters[5], (int)ww.mainParameters[7]);
                     }
                     else
                     {
                         ww.StartHarpoon(ww.mainParameters[0], ww.mainParameters[1], ww.mainParameters[3], ww.mainParameters[4], ww.mainParameters[9], false, (int)ww.mainParameters[5], (int)ww.mainParameters[7]);
                     }
                 }
             }
         }
     }


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

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

112 People are following this question.

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

Related Questions

Simple Coroutine doesn't finish 1 Answer

Line of code skips randomly at times? 1 Answer

Using Coroutine rather than Update to Check Whether Time Passed 1 Answer

assertion failed on expression: 'GetSystemInterested(transform, system) != enable' 1 Answer

Each update runs my code 6 times per line. Is it a bug? 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