public void SpawnFT( ) { Debug.Log("Spawning FT..."); GameObject go = Instantiate(floatingText.gameObject, new Vector3(-22, 0, 0), Quaternion.identity); FloatingText ft = go.GetComponent <FloatingText>( ); ft.SetPrameters(Random.Range(1, 10).ToString( ), true, 1.0f, 1.0f, Color.white); }
/// <summary> /// Shows a standard Floating Text. /// </summary> /// <param name="position">In-game world start position.</param> /// <param name="text">Text to display.</param> /// <param name="tintColor">Text color.</param> /// <param name="speedMultiplier"></param> /// <param name="size">Scale of the text object.</param> public GameObject ShowFloatingTextStandard(Vector3 position, string text, Color tintColor, float speedMultiplier = 1.0f, float scale = 1.0f) { GameObject go = Instantiate(floatingTextStandard, position, Quaternion.identity); FloatingText ft = go.GetComponent <FloatingText>( ); ft.SetPrameters(text, tintColor, speedMultiplier, scale); return(go); }
/// <summary> /// Applies damage to current HP. Respects HP restrictions and fires events if necessary. /// </summary> /// <param name="damage">Amount of taken damage.</param> public void DoDamage(float damage, Vector2 contact, bool special = false) { if (!canBeDamaged) { return; } if (!special) { onDamage.Invoke( ); } ChangeHP(-damage); if (animator) { animator.SetTrigger("damage"); } if (damageParticles) { Instantiate(damageParticles, transform.position, Quaternion.Euler(0f, 0f, 0f)); } if (hpBar && !hpBar.gameObject.activeSelf && hideHpBar) { hpBar.gameObject.SetActive(true); if (hpBarUnder) { hpBarUnder.gameObject.SetActive(true); } } if (floatingTextDamage) { GameObject go = Instantiate(floatingTextDamage, contact, Quaternion.identity); FloatingText ft = go.GetComponent <FloatingText>( ); ft.SetPrameters(damage.ToString( ), floatingTextLeftDir, 1.0f, 1.0f, Color.white); } if (delayNextDamage) { canBeDamaged = false; Invoke(nameof(CanBeDamaged), nextDamageDelay); } }
/// <summary> /// Adds health. Respects HP restrictions and fires events if necessary. /// </summary> /// <param name="change">Amount of HP change. Negative values for damage, positive for healing.</param> public void Heal(float heal) { onHeal.Invoke( ); if (floatingTextHeal) { float healed = heal; if (CurrentHP + heal > maxHP) { healed = maxHP - CurrentHP; } GameObject go = Instantiate(floatingTextHeal, transform.position, Quaternion.identity); FloatingText ft = go.GetComponent <FloatingText>( ); ft.SetPrameters($"+{healed}", floatingTextLeftDir, 1.0f, 1.0f, Color.white); } ChangeHP(heal); }