void UpdateCooldown(int hotBarSpot, bool isInScene) { attackLibrary currentAttack = null; float cooldownVal = 0; foreach (GameObject obj in GameObject.FindGameObjectsWithTag("attacks")) { if (obj.GetComponent <attackLibrary>() != null && isInScene) { currentAttack = obj.GetComponent <attackLibrary>(); cooldownVal = currentAttack.GetSavedValues()[currentAttack.cooldownSpot]; cooldownArr[hotBarSpot] = cooldownVal; } else { cooldownVal = cooldownArr[hotBarSpot]; } //Debug.Log(attack0.GetComponent<attackLibrary>().GetSavedValues()[attack0.GetComponent<attackLibrary>().cooldownSpot] + " Index: " + cooldownArr[0]); } if (hotBarSpot == 0) { GameObject.FindGameObjectWithTag("h0").GetComponent <Image>().fillAmount = 1 - cooldownVal; } else if (hotBarSpot == 1) { GameObject.FindGameObjectWithTag("h1").GetComponent <Image>().fillAmount = 1 - cooldownVal; } else if (hotBarSpot == 2) { GameObject.FindGameObjectWithTag("h2").GetComponent <Image>().fillAmount = 1 - cooldownVal; } else if (hotBarSpot == 3) { GameObject.FindGameObjectWithTag("h3").GetComponent <Image>().fillAmount = 1 - cooldownVal; } else if (hotBarSpot == 4) { GameObject.FindGameObjectWithTag("h4").GetComponent <Image>().fillAmount = 1 - cooldownVal; } else if (hotBarSpot == 5) { GameObject.FindGameObjectWithTag("h5").GetComponent <Image>().fillAmount = 1 - cooldownVal; } else if (hotBarSpot == 6) { GameObject.FindGameObjectWithTag("h6").GetComponent <Image>().fillAmount = 1 - cooldownVal; } else if (hotBarSpot == 7) { GameObject.FindGameObjectWithTag("h7").GetComponent <Image>().fillAmount = 1 - cooldownVal; } else if (hotBarSpot == 8) { GameObject.FindGameObjectWithTag("h8").GetComponent <Image>().fillAmount = 1 - cooldownVal; } }
public void UpdateCurrentItem(int curPoint) { attackLibrary currentAttack = null; foreach (GameObject obj in GameObject.FindGameObjectsWithTag("attacks")) { if (obj.GetComponent <attackLibrary>() != null) { currentAttack = obj.GetComponent <attackLibrary>(); currentAttack.SetSavedValuesAtSpot(currentAttack.cooldownSpot, cooldownArr[curPoint]); } } try { savedValuesArr[currentAttack.cooldownSpot, curPoint] = cooldownArr[curPoint]; if (curPoint == 0 && currentAttack != null && attack0 != null) { attack0.GetComponent <attackLibrary>().SetSavedValuesAtSpot(currentAttack.cooldownSpot, cooldownArr[curPoint]); for (int i = 0; i < 10; i++) { attack0.GetComponent <attackLibrary>().SetSavedValuesAtSpot(i, savedValuesArr[i, 0]); } } else if (curPoint == 1 && currentAttack != null && attack1 != null) { attack1.GetComponent <attackLibrary>().SetSavedValuesAtSpot(currentAttack.cooldownSpot, cooldownArr[curPoint]); for (int i = 0; i < 10; i++) { if (i != currentAttack.cooldownSpot) { attack1.GetComponent <attackLibrary>().SetSavedValuesAtSpot(i, savedValuesArr[i, 1]); } } } else if (curPoint == 2 && currentAttack != null && attack2 != null) { for (int i = 0; i < 10; i++) { attack2.GetComponent <attackLibrary>().SetSavedValuesAtSpot(i, savedValuesArr[i, 2]); } } else if (curPoint == 3 && currentAttack != null && attack3 != null) { for (int i = 0; i < 10; i++) { attack3.GetComponent <attackLibrary>().SetSavedValuesAtSpot(i, savedValuesArr[i, 3]); } } else if (curPoint == 4 && currentAttack != null && attack4 != null) { for (int i = 0; i < 10; i++) { attack4.GetComponent <attackLibrary>().SetSavedValuesAtSpot(i, savedValuesArr[i, 4]); } } else if (curPoint == 5 && currentAttack != null && attack5 != null) { for (int i = 0; i < 10; i++) { attack5.GetComponent <attackLibrary>().SetSavedValuesAtSpot(i, savedValuesArr[i, 5]); } } else if (curPoint == 6 && currentAttack != null && attack6 != null) { for (int i = 0; i < 10; i++) { attack6.GetComponent <attackLibrary>().SetSavedValuesAtSpot(i, savedValuesArr[i, 6]); } } else if (curPoint == 7 && currentAttack != null && attack7 != null) { for (int i = 0; i < 10; i++) { attack7.GetComponent <attackLibrary>().SetSavedValuesAtSpot(i, savedValuesArr[i, 7]); } } else if (curPoint == 8 && currentAttack != null && attack8 != null) { for (int i = 0; i < 10; i++) { attack8.GetComponent <attackLibrary>().SetSavedValuesAtSpot(i, savedValuesArr[i, 8]); } } } catch (Exception e) { debugger += e; } }
/* Author - Matt Braden * updates the attacks to account for any changes */ public void updateAttacks() { //IMPORTANT!!!! in order to use try/catch, you need to first import it by typing "using System" at the top try { lib0 = attack0.GetComponent(typeof(attackLibrary)) as attackLibrary; GameObject.FindGameObjectWithTag("h0").GetComponent <Image>().overrideSprite = lib0.icon; } catch (Exception e) { //if an exception is made, it skips the code and adds to the error string debugger += "\n" + e; GameObject.FindGameObjectWithTag("h0").GetComponent <Image>().overrideSprite = null; } try { lib1 = attack1.GetComponent(typeof(attackLibrary)) as attackLibrary; GameObject.FindGameObjectWithTag("h1").GetComponent <Image>().overrideSprite = lib1.icon; } catch (Exception e) { debugger += "\n" + e; GameObject.FindGameObjectWithTag("h1").GetComponent <Image>().overrideSprite = null; } try { lib2 = attack2.GetComponent(typeof(attackLibrary)) as attackLibrary; GameObject.FindGameObjectWithTag("h2").GetComponent <Image>().overrideSprite = lib2.icon; } catch (Exception e) { debugger += "\n" + e; GameObject.FindGameObjectWithTag("h2").GetComponent <Image>().overrideSprite = null; } try { lib3 = attack3.GetComponent(typeof(attackLibrary)) as attackLibrary; GameObject.FindGameObjectWithTag("h3").GetComponent <Image>().overrideSprite = lib3.icon; } catch (Exception e) { debugger += "\n" + e; GameObject.FindGameObjectWithTag("h3").GetComponent <Image>().overrideSprite = null; } try { lib4 = attack4.GetComponent(typeof(attackLibrary)) as attackLibrary; GameObject.FindGameObjectWithTag("h4").GetComponent <Image>().overrideSprite = lib4.icon; } catch (Exception e) { debugger += "\n" + e; GameObject.FindGameObjectWithTag("h4").GetComponent <Image>().overrideSprite = null; } try { lib5 = attack5.GetComponent(typeof(attackLibrary)) as attackLibrary; GameObject.FindGameObjectWithTag("h5").GetComponent <Image>().overrideSprite = lib5.icon; } catch (Exception e) { debugger += "\n" + e; GameObject.FindGameObjectWithTag("h5").GetComponent <Image>().overrideSprite = null; } try { lib6 = attack6.GetComponent(typeof(attackLibrary)) as attackLibrary; GameObject.FindGameObjectWithTag("h6").GetComponent <Image>().overrideSprite = lib6.icon; } catch (Exception e) { debugger += "\n" + e; GameObject.FindGameObjectWithTag("h6").GetComponent <Image>().overrideSprite = null; } try { lib7 = attack7.GetComponent(typeof(attackLibrary)) as attackLibrary; GameObject.FindGameObjectWithTag("h7").GetComponent <Image>().overrideSprite = lib7.icon; } catch (Exception e) { debugger += "\n" + e; GameObject.FindGameObjectWithTag("h7").GetComponent <Image>().overrideSprite = null; } try { lib8 = attack8.GetComponent(typeof(attackLibrary)) as attackLibrary; GameObject.FindGameObjectWithTag("h8").GetComponent <Image>().overrideSprite = lib8.icon; } catch (Exception e) { debugger += "\n" + e; GameObject.FindGameObjectWithTag("h8").GetComponent <Image>().overrideSprite = null; } }