public void Heal(float amount) { GameObject newDamage = Instantiate(damageText, Camera.main.WorldToScreenPoint(transform.position + new Vector3(Random.Range(-.5f, .5f), 1, 0)), Quaternion.identity, FindObjectOfType <Canvas>().transform); TextMeshProUGUI textMesh = newDamage.GetComponent <TextMeshProUGUI>(); AttackText newText = newDamage.GetComponent <AttackText>(); textMesh.text = Mathf.RoundToInt(amount * 10) + " !"; textMesh.color = new Color(0.3177287f, 0.7924528f, 0.4481168f); newText.baseColor = new Color(0.3177287f, 0.7924528f, 0.4481168f); // HEAL FX Instantiate(healParticle, transform.position, new Quaternion()); health += amount; healthBar.value = health; }
public virtual bool Damage(float amount) { if (amount < 0) { amount = 0; } health -= amount; if (health > 0) { GameObject newDamage = Instantiate(damageText, Camera.main.WorldToScreenPoint(transform.position + new Vector3(Random.Range(-.5f, .5f), 1, 0)), Quaternion.identity, FindObjectOfType <Canvas>().transform); TextMeshProUGUI textMesh = newDamage.GetComponent <TextMeshProUGUI>(); AttackText newText = newDamage.GetComponent <AttackText>(); if (amount > 0) { FindAggroTarget(); // DAMAGE FX HERE int randomParticle = Random.Range(0, 2); Instantiate(damageParticle[randomParticle], transform.position, new Quaternion()); textMesh.text = Mathf.RoundToInt(amount * 10) + "!"; textMesh.color = new Color(0.7924528f, 0.1831613f, 0.2159052f); newText.baseColor = new Color(0.7924528f, 0.1831613f, 0.2159052f); } else { // BLOCK FX HERE Instantiate(blockParticle, transform.position, new Quaternion()); textMesh.text = "Blocked!"; } healthBar.value = health; return(false); } else { Die(); return(true); } }