Exemplo n.º 1
0
    private void Health_OnHealthModified(Health.HealthData healthData)
    {
        if (!gameObject.activeInHierarchy)
        {
            return;
        }

        // Check if health got decreased or added and play the according animation.
        // TODO: Add 'IncreaseHealth' animation, it just plays the decrease animation now.
        if (anim)
        {
            anim.SetTrigger(foregroundHealthBar.fillAmount > healthData.percentageHealth ? "DecreaseHealth" : "DecreaseHealth");
        }

        foregroundHealthBar.fillAmount = healthData.percentageHealth;
        StartCoroutine(LerpBackgroundHealthBar(healthData.percentageHealth));

        if (healthText)
        {
            healthText.text = healthData.currentHealth + "/" + healthData.maxHealth;
        }

        if (healthData.amountHealthChanged != null && showDamageText)
        {
            DamageText newDamageText = ObjectPooler.instance.GrabFromPool("DamageText", transform.position, transform.rotation).GetComponent <DamageText>();
            if (healthData.isInvinsible && healthData.amountHealthChanged <= 0)
            {
                newDamageText.Initialise("Dodge");
            }
            else
            {
                newDamageText.Initialise(healthData);
            }
        }
    }
Exemplo n.º 2
0
    public void Initialise(Health.HealthData healthData)
    {
        SetTextColor(healthData);

        damageText.text     = Mathf.Abs((int)healthData.amountHealthChanged).ToString();
        transform.position += new Vector3(Random.Range(-randomSpawnOffsetX, randomSpawnOffsetX), Random.Range(-randomSpawnOffsetY, randomSpawnOffsetY), 0);

        newPos   = transform.position;
        newColor = damageText.color;

        transform.localScale  = originalScale;
        transform.localScale *= Remap(Mathf.Abs((int)healthData.amountHealthChanged), 0, 10000, 1, 4f);
    }
Exemplo n.º 3
0
    private void SetTextColor(Health.HealthData healthData)
    {
        // Damage.
        if (healthData.amountHealthChanged < 0)
        {
            switch (healthData.damageType)
            {
            case Stats.DamageType.Melee:

                damageText.color = Color.red;
                break;

            case Stats.DamageType.Ranged:

                damageText.color = Color.red;
                break;

            case Stats.DamageType.Secondary:

                damageText.color = Color.red;
                break;

            case Stats.DamageType.AOE:

                damageText.color = Color.red;
                break;

            case Stats.DamageType.Bleed:

                damageText.color = new Color(1, 0.44f, 0.25f, 1);
                break;

            case Stats.DamageType.Poison:

                damageText.color = Color.yellow;
                break;
            }
        }
        // Nothing.
        else if (healthData.amountHealthChanged == 0)
        {
            damageText.color = Color.white;
        }
        // Heal.
        else if (healthData.amountHealthChanged > 0)
        {
            damageText.color = Color.green;
        }
    }