public void TakeDamage(Damage d, int damage) { if (cbp > 0) // If there is a barrier attack barrier first; take damage to hp { if (cbp > damage) { cbp = cbp - damage; damage = 0; } else if (damage > cbp) { damage = damage - cbp; } } if (cbp <= 0 && chp > 0 && damage > 0) // If there is no barrier, has more than 0 current hp, and there is damage to deal; take damage to hp { chp = chp - damage; } if (DamageTextManager.IsOkToCreate()) { var dui = GameObject.FindGameObjectWithTag("DamageText"); GameObject dtui = Instantiate(dui, dui.transform.parent.parent) as GameObject; Vector2 cam = Camera.main.WorldToScreenPoint(transform.position); dtui.transform.position = cam; dtui.AddComponent <DamageText_UI>().SetDamage(d, damage); } CheckVitals(); KnockBack(); }
void Update() { SetChaser(); if (!DamageTextManager.IsOkToCreate()) { Destroy(gameObject); } }
public void OnTriggerStay2D(Collider2D col) { if (col.tag == "Monster" && tag == "PHITBOX") { var b = GetComponentInParent <Player_Main>(); if (!b.invulnerable) { Damage d = null; var m = col.GetComponent <Monster>(); if (m.mobElement == Damage.DamageType.Poison) { Damage_OT dot = new Damage_OT(Damage_OT.Damage_OTType.Poison, (int)(Random.Range(m.minDamage, m.maxDamage) / 5f), 1.00f); GameObject debuff = Instantiate(new GameObject(), b.transform); debuff.AddComponent <De_Buff>().InitializeDeBuff(dot); d = new Damage(m.mobElement, m.minDamage / 3, m.maxDamage / 3); } else { d = new Damage(m.mobElement, m.minDamage, m.maxDamage); } Resistance r = (GetComponentInParent <Player_Stats>().GetResistanceForType(m.mobElement)); int x = Damage_Calculator.CalculateElementDamageToPlayer(m, d, r); b.TakeDamage(x); var dui = GameObject.FindGameObjectWithTag("DamageText"); if (DamageTextManager.IsOkToCreate()) { GameObject dtui = Instantiate(dui, dui.transform.parent.parent) as GameObject; Vector2 cam = Camera.main.WorldToScreenPoint(transform.position); dtui.transform.position = cam; dtui.AddComponent <DamageText_UI>().SetDamage(d, x, true); } } } }
public void SetDamage(Damage_OT damage, int amount, bool monster = false) { if (DamageTextManager.IsOkToCreate()) { GetComponent <Rigidbody2D>().simulated = true; if (monster) { GetComponent <UnityEngine.UI.Text>().fontStyle = FontStyle.Italic; } else if (!monster) { GetComponent <UnityEngine.UI.Text>().fontStyle = FontStyle.Normal; } GetComponent <UnityEngine.UI.Text>().color = Color.black; chaserColor = (!monster) ? SetDamageOTColor(damage.GetDamage_OTType()) : Mob; GetComponent <UnityEngine.UI.Text>().fontSize = 4; GetComponent <UnityEngine.UI.Text>().text = amount.ToString(); GetComponent <Rigidbody2D>().velocity = new Vector2(Random.Range(-200, 200), 200); } else { Destroy(gameObject); } }