Пример #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        var attack = collision.gameObject.GetComponent <Attack>();

        if (attack != null && collision.gameObject.tag != gameObject.tag)
        {
            var damage = Mathf.Max(attack.Damage - Defence, 1f);

            health = Mathf.Clamp(health - damage, 0, HealthMax);
            RefreshHealth();

            if (Popup != null && gameObject.tag != "Player")
            {
                Popup.CreatePopup(damage, Color.red);
            }

            if (health <= 0f)
            {
                if (gameObject.tag == "Player")
                {
                    SceneManager.LoadScene(SceneManager.GetActiveScene().name);
                }

                if (Drop != null)
                {
                    Drop.DropStuff();
                }

                Destroy(gameObject);
            }
        }

        var powerup = collision.gameObject.GetComponent <Powerup>();

        if (powerup != null)
        {
            HealthMax += powerup.MaxHealth;
            health     = Mathf.Clamp(health + powerup.Health, 0, HealthMax);

            RefreshHealth();

            if (powerup.MaxHealth > 0f)
            {
                Popup.CreatePopup(powerup.MaxHealth, powerup);
            }
            else if (powerup.Health > 0f)
            {
                Popup.CreatePopup(powerup.Health, powerup);
            }

            if (powerup.Defence > 0f)
            {
                Popup.CreatePopup(powerup.Defence, powerup);
            }

            Destroy(powerup.gameObject);
        }
    }
Пример #2
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        var powerup = collision.gameObject.GetComponent <Powerup>();

        if (powerup != null)
        {
            Speed += powerup.Speed;

            BagCain.AddChain(powerup.Chain);

            if (powerup.Speed > 0)
            {
                Popup.CreatePopup(powerup.Speed, powerup);
            }

            if (powerup.Chain > 0)
            {
                Popup.CreatePopup(powerup.Chain, powerup);
            }

            Destroy(powerup.gameObject);
        }
    }
Пример #3
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        var powerup = collision.gameObject.GetComponent <Powerup>();

        if (powerup != null)
        {
            Damage += powerup.Attack;

            if (Popup != null && powerup.Attack > 0)
            {
                Popup.CreatePopup(powerup.Attack, powerup);
            }

            Destroy(powerup.gameObject);
        }
    }