// Update is called once per frame void Update() { AnimatorStateInfo asi = animator.GetCurrentAnimatorStateInfo(0); if (battle && !asi.IsName("Damage") && !animator.IsInTransition(0)) { if (healthBar == null) { healthBar = (gameObject.transform.FindChild("EnemyHealth").FindChild("EnemyLife")).gameObject; } if (healthBar.transform.localScale.x * 100 != hp) { Vector3 temp = healthBar.transform.localScale; temp.x = hp / 100f; if (hp / 100 < 0) { temp.x = 0; } healthBar.transform.localScale = temp; } if (hp <= 0 && !morri) { turno = false; animator.Play("Death"); print("tocando morte"); morri = true; } else if (hp <= 0 && morri && asi.normalizedTime >= 0.9f) { int rr = Random.Range(0, 5); victory.SetActive(true); buttonContinue.SetActive(true); if (rr != 5) { imageItem.SetActive(true); imageItem.GetComponent <Image>().sprite = sprite[rr]; GameObject inventory = GameObject.FindGameObjectWithTag("Canvas").transform.FindChild("Panel - Inventory(Clone)").gameObject; Inventory mainInventory = inventory.GetComponent <Inventory>(); mainInventory.addItemToInventory(item[rr]); } battle = false; PlayerScript.battle = false; } if (battle && turno) { print("eh o turno dele e ele tem " + hp + " de vida"); if (mana < 10) { if (!ataquei) { animator.Play("Attack"); ataquei = true; } else if (ataquei && !asi.IsName("Attack")) { PlayerScript.decreaseHp(damage); turno = false; PlayerScript.turno = true; PlayerScript.battle = true; ataquei = false; } } else { if (!ataquei && !useiSkill) { int skill = Random.Range(0, 8); if (randomSkill[skill] == 1) { animator.Play("Attack"); ataquei = true; } else { animator.Play("Skill"); useiSkill = true; } } else if (ataquei && !asi.IsName("Attack")) { PlayerScript.decreaseHp(damage); PlayerScript.turno = true; PlayerScript.battle = true; turno = false; ataquei = false; } else if (useiSkill && !asi.IsName("Skill")) { PlayerScript.decreaseHp(damage * 1.5f); mana -= 25; PlayerScript.turno = true; PlayerScript.battle = true; turno = false; useiSkill = false; } } if (!turno) { Text turnText = (Camera.main.transform.FindChild("Canvas").FindChild("Turn").gameObject).GetComponent <Text>(); turnText.text = "Your Turn"; } } } }