Ejemplo n.º 1
0
    //args
    //0 dmg
    //1 arp - deleted
    //2 pointx
    //3 pointy
    void Damage(int[] arg)
    {
        Vector2 hitPoint = new Vector2(arg[2], arg[3]);

        if (isPlayer)
        {
            if (shield.used)
            {
                AudioSource.PlayClipAtPoint(shieldSound, new Vector3(3, 0, 0));
                if (arg[0] <= shield.energy)
                {
                    shield.energy -= arg[0];
                    arg[0]         = 0;
                }
                else
                {
                    arg[0]       -= Mathf.FloorToInt(shield.energy);
                    shield.energy = 0;
                }
            }
        }

        if (arg[0] > 0)
        {
            hp -= arg[0];
            if (isPlayer)
            {
                AudioSource.PlayClipAtPoint(hitSound, new Vector3(3, 0, 0));
            }
            if (hitEffect)
            {
                Instantiate(hitEffect, hitPoint, transform.rotation);
            }
        }

        if (isPlayer)
        {
            AdjustUI();
        }
        else
        {
            hpbar.target = gameObject;
            hpbar.UpdateInt();
        }


        if (hp <= 0)
        {
            Annihilation();
        }
    }