void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.CompareTag("Player") && this.CompareTag("Obstacle"))
        {
            //need to play a sound and show the explosion effect on both the asteroid and player
            ObjectPool.DeactivateObject(this.gameObject);
            ObjectPool.DeactivateObject(col.gameObject);
            sm.PlaySound(sm.sounds[0]);
            Instantiate(gm.aExplosion, this.transform.position, this.transform.rotation);
            Instantiate(gm.pExplosion, col.transform.position, col.transform.rotation);
            GameManager.gameOver = true;
        }

        if (col.gameObject.CompareTag("Player") && this.CompareTag("Power"))
        {
            //need to play sound
            ObjectPool.DeactivateObject(this.gameObject);
            sm.PlaySound(sm.sounds[1]);
            powerBar.AddPower(5);
        }

        if (col.gameObject.CompareTag("Player") && this.CompareTag("BigPower"))
        {
            //need to play sound
            ObjectPool.DeactivateObject(this.gameObject);
            sm.PlaySound(sm.sounds[2]);
            powerBar.AddPower(15);
        }

        if (col.gameObject.CompareTag("Player") && this.CompareTag("TimePocket"))
        {
            //need to play sound
            ObjectPool.DeactivateObject(this.gameObject);
            sm.PlaySound(sm.sounds[3]);
            GameManager.speed             = 2.5f;
            GameManager.powerSpeed        = 3f;
            GameManager.objectSpawn       = .5f;
            GameManager.enteredTimePocket = true;
        }

        if (col.gameObject.CompareTag("Player") && this.CompareTag("WormHole"))
        {
            //need to play sound
            ObjectPool.DeactivateObject(this.gameObject);
            sm.PlaySound(sm.sounds[4]);
            GameManager.LightspeedEffect();
        }

        if (col.gameObject.CompareTag("Player") && this.CompareTag("Wrench"))
        {
            //need to play sound
            ObjectPool.DeactivateObject(this.gameObject);
            sm.PlaySound(sm.sounds[5]);
            GameManager.powerDecay = 3;
        }
    }
Exemplo n.º 2
0
    public bool ChangePower(int value)
    {
        int count = 0;

        if (_power + value > _maxPower)
        {
            count  = _maxPower - _power;
            _power = _maxPower;
        }
        else if (_power + value >= 0)
        {
            count   = value;
            _power += value;
        }

        if (count > 0)
        {
            PowerBarRef.AddPower(count);
        }
        else
        {
            PowerBarRef.RemovePower(-count);
        }
        return(count != 0);
    }