public void ShowDmgText(Vector3 pos, float dmg, int type, bool isReinforced) { GameObject text = GameManager.Inst().ObjManager.MakeObj("DamageText"); text.transform.position = pos; text.SetActive(true); DamageText dmgText = text.GetComponent <DamageText>(); if (type == (int)DamageType.PLAYERHEAL) { dmgText.SetPlusText(dmg); } else { dmgText.SetText(dmg); } dmgText.SetSize(dmgText.DefaultSize); dmgText.SetColor(type); if (isReinforced) { //text.transform.localScale = Vector3.one * 2.0f; dmgText.SetSize(48); dmgText.SetColor((int)DamageType.REINFORCED); } ActivationTimer timer = text.GetComponent <ActivationTimer>(); timer.IsStart = true; }
public void DisplayCustomTextAbove(CombatEntity entity, string text, bool bUseUnscaleTime = true, Color customColor = default(Color), int fontSize = -1) { if (_dmgTextPrefab == null) { _dmgTextPrefab = Resources.Load <GameObject>("Prefab/DamageText"); } entity.FindCharacterSprite(); if (entity.CharacterSprite != null) { Vector2 rendererPosition = entity.CharacterSprite.RendererPosition; rendererPosition.y += 1.8f; GameObject gameObject = UnityEngine.Object.Instantiate(_dmgTextPrefab, rendererPosition, Quaternion.identity); DamageText damageText = gameObject.GetComponent <DamageText>(); damageText.SetText(text); if (customColor.a > 0f) { damageText.SetColor(customColor); } if (fontSize >= 0) { damageText.SetSize(fontSize); } if (!bUseUnscaleTime) { gameObject.GetComponentInChildren <UI2DFloatyText>()._useUnscaleTime = false; return; } } else { Debug.LogError("Missing CharacterSprite"); } }
public static void CreateDamageText(int damage, float x, float y) { DamageText instance = Instantiate(damageText); Vector2 screenPosition = Camera.main.WorldToScreenPoint(new Vector2(x, y)); instance.transform.SetParent(canvas.transform, false); instance.transform.position = screenPosition; if (damage < 0) //Healing { instance.SetColor(Color.green); instance.SetText((-damage).ToString()); } else { instance.SetText(damage.ToString()); } }
public void Heal(float health) { currentHealth = Mathf.Min(currentHealth + health, MaxHealth); FlashGreen(); if (HealFX) { Instantiate(HealFX, this.transform); } GameObject ht = (GameObject)Instantiate(damageTextPrefab, this.gameObject.transform.position, Camera.main.transform.rotation); DamageText script = ht.gameObject.GetComponent <DamageText>(); script.SetColor(Color.green); script.SetText(Mathf.Round(health).ToString()); UpdateHealthUI(); }
public virtual void TakeDamage(float damage, bool isCriticalHit) { if (currentHealth - damage > 0) { currentHealth = Mathf.Max(currentHealth - damage, 0); FlashRed(); GameObject dt = (GameObject)Instantiate(damageTextPrefab, this.gameObject.transform.position + Vector3.up * this.gameObject.transform.localScale.y / 2, Camera.main.transform.rotation); DamageText script = dt.gameObject.GetComponent <DamageText>(); if (isCriticalHit) { script.SetColor(Color.blue); } script.SetText(Mathf.Round(damage).ToString()); } else { Die(); } UpdateHealthUI(); }