Beispiel #1
0
 public bool SwitchWeapon(int weapon_num)
 {
     if (selected_weapon == weapon_num)
     {
         Debug.Log("Already equipped!");
         return(false);
     }
     if (weapon_num >= 0 && weapon_num < weapon_slots && player_weapons[weapon_num] != null)           //Valid weapon
     {
         if (unlocked_weapons[weapon_num])
         {
             GunController gc = player_weapons[weapon_num].GetComponent <GunController>();
             if (gc.ammo_count >= gc.ammo_cost)                     //Enough ammo
             {
                 gun_ctrl.Deselect();
                 selected_weapon = weapon_num;
                 gun_ctrl        = gc;
                 gun_ctrl.Select(1.0f);                       //TODO: Replace with proper animation time (swap out + swap in)
                 return(true);
             }
             else
             {
                 Debug.Log("Not enough ammo!");
                 return(false);
             }
         }
         else
         {
             Debug.Log("Not unlocked!");
             return(false);
         }
     }
     else
     {
         Debug.Log("Error: Invalid weapon slot.");
         return(false);
     }
 }