示例#1
0
 // Return powerup to a pool based on its Type
 public bool ReturnPowerUp(PowerupBase powerup)
 {
     if (powerup.PowerType == PowerupBase.Type.Health)
     {
         return(_healthPowerupPool.ReturnObject(powerup.gameObject));
     }
     else
     {
         return(_weaponPowerupPool.ReturnObject(powerup.gameObject));
     }
 }
示例#2
0
        protected override void Die()
        {
            base.Die();

            GameManager.Instance.IncrementScore(_score);

            if (LevelController.Current != null)
            {
                LevelController.Current.EnemyDestroyed();

                // Attempt to spawn a powerup
                PowerupBase powerup = LevelController.Current.GetPowerUp();
                if (powerup != null)
                {
                    // Place powerup on enemy position
                    powerup.transform.position = transform.position;
                }
            }
        }
示例#3
0
        public PowerupBase GetPowerUp()
        {
            // Attempt powerup spawn
            float powerupSpawn = Random.value;

            if (powerupSpawn > _powerupChance)
            {
                return(null);
            }

            GameObject result = null;

            // Randomize powerup type
            float type = Random.value;

            if (type < 0.5f)
            {
                result = _healthPowerupPool.GetPooledObject();
            }
            else
            {
                result = _weaponPowerupPool.GetPooledObject();
            }

            if (result != null)
            {
                PowerupBase powerup = result.GetComponent <PowerupBase>();
                if (powerup == null)
                {
                    Debug.LogError("Powerup component could not be found from the object fetched from the pool.");
                }

                return(powerup);
            }

            return(null);
        }