コード例 #1
0
    private void Damage(float[] attackDetails)
    {
        if (!invincible)
        {
            currentHealth -= attackDetails[0];
            int direction;
            hitPause.Pause();
            HealthManager.instance.SetHealth(currentHealth);

            if (attackDetails[1] < transform.position.x)
            {
                direction = 1;
            }
            else
            {
                direction = -1;
            }

            cc.KnockBack(direction);

            if (currentHealth <= 0.0f)
            {
                hitPause.Pause();
                string level = "Death";
                // go to complete screen
                Application.LoadLevel(level);
            }
        }
    }
コード例 #2
0
    // use array to receive multiple parameters from player object
    private void Damage(float[] attackDetails)
    {
        if (gameObject != null)
        {
            // 0 in the array is the amount of damage being recieved
            currentHealth -= attackDetails[0];

            // calculates whether player is on left or right side of the enemy
            if (attackDetails[1] > rb.transform.position.x)
            {
                damageDirection = -1;
            }
            else
            {
                damageDirection = 1;
            }

            // enemy is still alive
            if (currentHealth > 0.0f)
            {
                //hitPause.Pause();
                SwitchState(State.Knockback);
            }
            else if (currentHealth <= 0.0f)
            {
                hitPause.Pause();
                SwitchState(State.Dead);
            }
        }
    }