Esempio n. 1
0
 private void HandleWeaponSelections()
 {
     if (Input.GetKeyDown(KeyCode.Alpha1))
     {
         m_CurrentGunSelection = GunSelection.MACHINEGUN;
         UpdateFireRate();
     }
     else if (Input.GetKeyDown(KeyCode.Alpha2))
     {
         m_CurrentGunSelection = GunSelection.ROCKET;
         UpdateFireRate();
     }
     else if (Input.GetKeyDown(KeyCode.Alpha3))
     {
         m_CurrentGunSelection = GunSelection.MISSILE;
         UpdateFireRate();
     }
 }
    //##############################################################################################
    // If any of the inputs are pressed, enable that gun and disable the previous
    //##############################################################################################
    void Update()
    {
        for (int i = 0, count = selections.Length; i < count; ++i)
        {
            GunSelection gunSelection = selections[i];

            if (Input.GetKeyDown(gunSelection.selectionKey) && i != previouslySelectedIndex)
            {
                // Disable the previous gun
                if (previouslySelectedIndex != INVALID_SELECTION)
                {
                    selections[previouslySelectedIndex].gun.enabled = false;
                }

                // Enable the current gun
                gunSelection.gun.enabled = true;

                previouslySelectedIndex = i;

                return;
            }
        }
    }