- Home /
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]);
}
}
}
}
}
Your answer
Follow this Question
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