public void takeDamage(float damage) { if (battleReady == true) { if (damage > 0 && currentHP - damage > 0) { currentHP -= damage; monsterAnimator.Play("damage"); Vector3 tmp = monsterHPSlider.transform.localScale; tmp.x = currentHP / maxHP; monsterHPSlider.transform.localScale = tmp; } else if (currentHP - damage <= 0) { currentHP = 0; this.transform.Find("Healthbar").gameObject.SetActive(false); this.GetComponent <Button>().onClick.RemoveAllListeners(); CancelInvoke(); monsterAnimator.Play("death"); StartCoroutine(FadeTo(0f, 1.0f)); GameObject newCoin = Instantiate(Resources.Load("Prefabs/Coin") as GameObject, this.transform.position, this.transform.rotation, this.transform.parent); Invoke("Despawn", 1f); } displayMonsterHP.text = RoundingUtils.GetShorthand(currentHP) + "/" + RoundingUtils.GetShorthand(maxHP); if (damage == GameData.sessionData.playerUpgrade.currentDamage) { FindObjectOfType <Player>().attack(); // Attack animation if it was dealt by player } } }
public void RefreshUI() { calculations = UpgradeUtils.CalculateUpgrade(upgradeName, upgrade.currentLevel, baseCost, heroUnlockOrder, FindObjectOfType <GameManager>().buyAmountDic[panelName]); UIDic[uiNames[1]].text = "(LVL: " + RoundingUtils.GetShorthand(upgrade.currentLevel) + ")"; UIDic[uiNames[2]].text = "Damage: " + RoundingUtils.GetShorthand(upgrade.currentDamage) + " DPS"; UIDic[uiNames[3]].text = RoundingUtils.GetShorthand(Mathf.Round(calculations[0])); UIDic[uiNames[4]].text = "+ " + RoundingUtils.GetShorthand(Mathf.Round(calculations[1])) + " DPS"; UIDic[uiNames[5]].text = "BUY: " + RoundingUtils.GetShorthand(Mathf.Round(calculations[2])); }
private void LoadUI() { monsterHPSlider = this.transform.Find("Healthbar").Find("HealthSlider").gameObject; displayMonsterHP = this.transform.Find("Healthbar").Find("HealthText").GetComponent <TextMeshProUGUI>(); monsterAnimator = this.GetComponent <Animator>(); this.GetComponent <Button>().onClick.AddListener(() => takeDamage(GameData.sessionData.playerUpgrade.currentDamage)); displayMonsterHP.text = RoundingUtils.GetShorthand(currentHP) + "/" + RoundingUtils.GetShorthand(maxHP); InvokeRepeating("HeroDamageRelay", 1, 1); }
private void SyncUI() { UIDic[uiNames[4]].GetComponentInChildren <TextMeshProUGUI>().text = RoundingUtils.GetShorthand(Mathf.Round(GameData.sessionData.playerData.gold)); UIDic[uiNames[5]].GetComponentInChildren <TextMeshProUGUI>().text = GameData.sessionData.playerData.stage.ToString(); UIDic[uiNames[6]].GetComponentInChildren <TextMeshProUGUI>().text = GameData.sessionData.playerData.monsterNum.ToString() + "/10"; UIDic[uiNames[7]].GetComponentInChildren <TextMeshProUGUI>().text = RoundingUtils.GetShorthand(GameData.sessionData.playerUpgrade.currentDamage); UIDic[uiNames[8]].GetComponentInChildren <TextMeshProUGUI>().text = RoundingUtils.GetShorthand(UpgradeUtils.GetTotalHeroDPS()); UpgradeUtils.UnlockNextHero(UIDic[uiNames[10]].gameObject); if (GameData.sessionData.heroUpgrades[0].unlocked == true && changeSprite == false) { Transform btn = UIDic[uiNames[3]].Find(uiNames[10]); btn.GetComponentInChildren <Button>().onClick.AddListener(() => TogglePanel(UIDic[uiNames[10]].gameObject)); btn.GetComponentInChildren <Image>().color = new Color32(50, 92, 233, 255); // Brighten the button btn.Find("Icon").GetComponent <Image>().sprite = Resources.Load <Sprite>("Art/HeroUpgrades") as Sprite; // Set button sprite btn.Find("Icon").GetComponent <Image>().color = new Color32(255, 255, 255, 200); // Change Icon Brightness changeSprite = true; } }
void Awake() { DontDestroyOnLoad(this); UpgradeUtils upUtils = new UpgradeUtils(); RoundingUtils roUtils = new RoundingUtils(); }