public static void CreateFloatingText(string text, Transform location) { DamageTextScript instance = Instantiate(popupTextPrefab); instance.transform.SetParent(canvas.transform, false); instance.SetText(text); }
public static void Initialize() { canvas = GameObject.Find("Canvas"); if (!popupTextPrefab) { popupTextPrefab = Resources.Load <DamageTextScript>("Prefabs/PopupTextParent"); } }
public static void CreateDamageText(float val, Transform location) { DamageTextScript instance = Instantiate(popup); instance.transform.SetParent(canvas.transform, false); instance.transform.position = location.position; instance.SetText(val); }
void SpawnDamageText(int damageDone, Vector3 position, Vector3 dir) { Vector3 randomLocation = new Vector3(Random.Range(-0.2f, 0.2f), Random.Range(-0.2f, 0.2f), 0); GameObject damageText = (GameObject)Instantiate(damageTextPrefab, position + dir / 2 + randomLocation, Quaternion.identity); DamageTextScript damageTextScript = damageText.GetComponent <DamageTextScript> (); damageTextScript.damage = damageDone; damageTextScript.duration = damageTextDuration; }
public void DisplayDamage(Vector3 textPosition, bool inverted = false) { TextMesh damageText = Instantiate(damageTextPrefab, textPosition, Quaternion.identity) as TextMesh; DamageTextScript damageScript = damageText.GetComponent <DamageTextScript> (); if (crit) { damageText.color = Color.red; damageText.transform.localScale = damageText.transform.localScale * 1.25f; } /*else * damageText.color = Color.white*/; damageText.text = damage.ToString(); damageScript.inverted = inverted; }
/// <summary> ///Deals Damage to the character depending on the damage type 0.True 1.AD 2.MD /// </summary> public void DealDamage(float damage, int damagetype) { if (damagetype == 0) //TrueDamage { DamageTextScript go = Instantiate(Resources.Load("Prefabs/Damage"), this.transform.position, this.transform.rotation) as DamageTextScript; go.Settext("" + damage); if (damage >= this.statsvalues.shield) { damage = Mathf.Clamp(damage - this.statsvalues.shield, 0, damage); this.statsvalues.shield = 0; this.statsvalues.life = Mathf.Clamp(this.statsvalues.life - damage, 0, this.statsvalues.totallife); } else { this.statsvalues.shield = Mathf.Clamp(this.statsvalues.shield - damage, 0, this.statsvalues.shield); } } else if (damagetype == 1) //AD - armor { if (this.statsvalues.armor >= 0) { if (((100 - this.statsvalues.reduceddamage) / 100) * damage >= this.statsvalues.shield) { damage = Mathf.Clamp(((100 - this.statsvalues.reduceddamage) / 100) * damage - this.statsvalues.shield, 0, ((100 - this.statsvalues.reduceddamage) / 100) * damage); this.statsvalues.shield = 0; this.statsvalues.life = Mathf.Clamp(this.statsvalues.life - (damage * (100 / (100 + this.statsvalues.armor))), 0, this.statsvalues.totallife); GameObject go = Instantiate(Resources.Load("Prefabs/Damage"), this.transform.position, Quaternion.Euler(new Vector3(60, 180, 0))) as GameObject; go.GetComponent <DamageTextScript>().Settext("" + (int)(damage * (100 / (100 + this.statsvalues.armor)))); } else { this.statsvalues.shield = Mathf.Clamp(this.statsvalues.shield - ((100 - this.statsvalues.reduceddamage) / 100) * damage, 0, this.statsvalues.shield); } } else { if (((100 - this.statsvalues.reduceddamage) / 100) * damage >= this.statsvalues.shield) { damage = Mathf.Clamp(((100 - this.statsvalues.reduceddamage) / 100) * damage - this.statsvalues.shield, 0, ((100 - this.statsvalues.reduceddamage) / 100) * damage); this.statsvalues.shield = 0; this.statsvalues.life = Mathf.Clamp(this.statsvalues.life - (damage * (2 - (100 / (100 - this.statsvalues.armor)))), 0, this.statsvalues.totallife); DamageTextScript go = Instantiate(Resources.Load("Prefabs/Damage"), this.transform.position, Quaternion.Euler(new Vector3(60, 180, 0))) as DamageTextScript; go.Settext("" + (int)(damage * (2 - (100 / (100 - this.statsvalues.armor))))); } else { this.statsvalues.shield = Mathf.Clamp(this.statsvalues.shield - ((100 - this.statsvalues.reduceddamage) / 100) * damage, 0, this.statsvalues.shield); } } } else if (damagetype == 2) //MD- mr { if (this.statsvalues.armor >= 0) { if (((100 - this.statsvalues.reduceddamage) / 100) * damage >= this.statsvalues.magicshield) { damage = Mathf.Clamp(((100 - this.statsvalues.reduceddamage) / 100) * damage - this.statsvalues.magicshield, 0, ((100 - this.statsvalues.reduceddamage) / 100) * damage); this.statsvalues.magicshield = 0; if (damage >= this.statsvalues.shield) { damage = Mathf.Clamp(damage - this.statsvalues.shield, 0, damage); this.statsvalues.shield = 0; this.statsvalues.life = Mathf.Clamp(this.statsvalues.life - (damage * (100 / (100 + this.statsvalues.mr))), 0, this.statsvalues.totallife); } else { this.statsvalues.shield = Mathf.Clamp(this.statsvalues.shield - damage, 0, this.statsvalues.shield); } } else { this.statsvalues.magicshield = Mathf.Clamp(this.statsvalues.magicshield - ((100 - this.statsvalues.reduceddamage) / 100) * damage, 0, this.statsvalues.shield); } } else { if (((100 - this.statsvalues.reduceddamage) / 100) * damage >= this.statsvalues.magicshield) { damage = Mathf.Clamp(((100 - this.statsvalues.reduceddamage) / 100) * damage - this.statsvalues.magicshield, 0, ((100 - this.statsvalues.reduceddamage) / 100) * damage); this.statsvalues.magicshield = 0; if (damage >= this.statsvalues.shield) { damage = Mathf.Clamp(damage - this.statsvalues.shield, 0, damage); this.statsvalues.shield = 0; this.statsvalues.life = Mathf.Clamp(this.statsvalues.life - (damage * (2 - (100 / (100 - this.statsvalues.mr)))), 0, this.statsvalues.totallife); } else { this.statsvalues.shield = Mathf.Clamp(this.statsvalues.shield - damage, 0, this.statsvalues.shield); } } else { this.statsvalues.magicshield = Mathf.Clamp(this.statsvalues.magicshield - ((100 - this.statsvalues.reduceddamage) / 100) * damage, 0, this.statsvalues.shield); } } } }
void Start() { canvas = GameObject.Find("BattleHUDCanvas"); popup = Resources.Load <DamageTextScript>("Prefabs/Battle/DamageText"); }