public void Activate(Powerup_Type type)
    {
        switch (type)
        {
        case Powerup_Type.Shield:
        {
            Set_State(PowerupState.Shield);
            break;
        }

        case Powerup_Type.Magnet:
        {
            Set_State(PowerupState.Magnet);
            break;
        }

        case Powerup_Type.Earthquake:
        {
            Set_State(PowerupState.Earthquake);
            break;
        }

        default:
        {
            break;
        }
        }
    }
Example #2
0
 public void SpawnPowerups()
 {
     if(isActive)
     {
         isSpawned = true;
         m_Despawn_Timer.Reset();
         m_Despawn_Timer.Add(GLOBAL_VALUES.POWERUP_DESPAWN_TIMER, true);
         int spawnAmount = 2;
         // Ensure we have enough spawners to spawn powerups
         if (spawnAmount > m_spawners.Count)
         {
             // wanting to spawn too many, scaling it down to possible number
             spawnAmount = m_spawners.Count;
         }
         // make sure you only spawn enough that you wont spawn doubles
         if (spawnAmount > System.Enum.GetNames(typeof(Powerup_Type)).Length)
         {
             spawnAmount = System.Enum.GetNames(typeof(Powerup_Type)).Length;
         }
         // pick random spawners (incase there are extra)
         List<int> chosen_spawner = new List<int>();
         List<Powerup_Type> chosen_powerups = new List<Powerup_Type>();
         while (chosen_spawner.Count < spawnAmount)
         {
             int num = Random.Range(0, (m_spawners.Count - 1));
             if (! chosen_spawner.Contains(num))
             {
                 chosen_spawner.Add(num);
             }
         }
         System.Array values = System.Enum.GetValues(typeof(Powerup_Type));
         while (chosen_powerups.Count < spawnAmount)
         {   
             int num = Random.Range(0, values.Length);
             Powerup_Type chosen = (Powerup_Type)values.GetValue(num);
             if (! chosen_powerups.Contains(chosen))
             {
                 chosen_powerups.Add(chosen);
             }
         }
         for(int i = 0; i < chosen_spawner.Count; i++)
         {
             GameObject prefab = null;
             Transform spawner = m_spawners[i].transform;
             switch(chosen_powerups[i])
             {
                 case Powerup_Type.Earthquake:
                     {
                         prefab = m_Prefab_Earthquake;
                         break;
                     }
                 case Powerup_Type.Magnet:
                     {
                         prefab = m_Prefab_Magnet;
                         break;
                     }
                 case Powerup_Type.Shield:
                     {
                         prefab = m_Prefab_Shield;
                         break;
                     }
             }
             Debug.Log("SPAWNING PU [" + prefab.name + "]");
             GameObject new_pu = GameObject.Instantiate(prefab, spawner.position, spawner.rotation) as GameObject;
             m_powerups.Add(new_pu);
         }
     }
 }