void Update()
    {
        if (Input.GetButtonDown("Pause"))
        {
            TogglePause();
        }

        if (Input.GetButtonDown("AbilityMenu"))
        {
            if (mode != GUIMode.ABILITY_MENU)
            {
                TogglePause();
                mode = GUIMode.ABILITY_MENU;
            }
            else
            {
                TogglePause();
            }
        }

        if (paused)
        {
            Time.timeScale = 0;
        }
        else
        {
            Time.timeScale = 1;
        }

        upgradeButton = Input.GetAxisRaw("Upgrade");
        //TODO ability activates immediately after assigning
        if (mode == GUIMode.ABILITY_PREVIEW)
        {
            if (Input.GetButton("Upgrade"))
            {
                if (Input.GetButtonDown("A1"))
                {
                    abCont.AddUpgrade(lastReceivedAbility, 0);
                    TogglePause();
                }
                else if (Input.GetButtonDown("A2"))
                {
                    abCont.AddUpgrade(lastReceivedAbility, 1);
                    TogglePause();
                }
                else if (Input.GetButtonDown("A3"))
                {
                    abCont.AddUpgrade(lastReceivedAbility, 2);
                    TogglePause();
                }
                else if (Input.GetButtonDown("A4"))
                {
                    abCont.AddUpgrade(lastReceivedAbility, 3);
                    TogglePause();
                }
            }
            else if (Input.GetButtonDown("A1"))
            {
                abCont.AddActive(lastReceivedAbility, 0);
                TogglePause();
            }
            else if (Input.GetButtonDown("A2"))
            {
                abCont.AddActive(lastReceivedAbility, 1);
                TogglePause();
            }
            else if (Input.GetButtonDown("A3"))
            {
                abCont.AddActive(lastReceivedAbility, 2);
                TogglePause();
                Input.ResetInputAxes();
            }
            else if (Input.GetButtonDown("A4"))
            {
                abCont.AddActive(lastReceivedAbility, 3);
                TogglePause();
            }
            else if (Input.GetButtonDown("Pause"))
            {
                //abCont.AddActive(lastReceivedAbility,-1);
                TogglePause();
            }
            else if (Input.GetButtonDown("P1"))
            {
                abCont.AddPassive(lastReceivedAbility, 0);
                TogglePause();
            }
            else if (Input.GetButtonDown("P2"))
            {
                abCont.AddPassive(lastReceivedAbility, 1);
                TogglePause();
            }
            else if (Input.GetButtonDown("P3"))
            {
                abCont.AddPassive(lastReceivedAbility, 2);
                TogglePause();
            }
            else if (Input.GetButtonDown("P4"))
            {
                abCont.AddPassive(lastReceivedAbility, 3);
                TogglePause();
            }
        }
        else if (mode == GUIMode.ABILITY_MENU)
        {
            if (abMenuCanSelect)
            {
                int hori = (int)Input.GetAxisRaw("Horizontal");
                int vert = -(int)Input.GetAxisRaw("Vertical");
                if (hori != 0 || vert != 0)
                {
                    int newSelection = abMenuSelected + hori + vert * abMenuRowSize;
                    if (newSelection >= 0 && newSelection < abCont.allAbilities.Count)
                    {
                        abMenuSelected  = newSelection;
                        abMenuCanSelect = false;
                        StartCoroutine(Timers.CountdownRealtime(selectionInterval, EnableSelect));
                        abMenuPosition = new Vector2(0, (abMenuSelected / abMenuRowSize) * iconSize);
                    }
                }
            }

            Ability selectedAb = abCont.allAbilities[abMenuSelected];
            if (Input.GetButton("Unupgrade"))
            {
                if (Input.GetButtonDown("A1"))
                {
                    abCont.RemoveUpgrade(0);
                }
                else if (Input.GetButtonDown("A2"))
                {
                    abCont.RemoveUpgrade(1);
                }
                else if (Input.GetButtonDown("A3"))
                {
                    abCont.RemoveUpgrade(2);
                }
                else if (Input.GetButtonDown("A4"))
                {
                    abCont.RemoveUpgrade(3);
                }
                else if (Input.GetButtonDown("P1"))
                {
                    abCont.RemovePassive(0);
                }
                else if (Input.GetButtonDown("P2"))
                {
                    abCont.RemovePassive(1);
                }
                else if (Input.GetButtonDown("P3"))
                {
                    abCont.RemovePassive(2);
                }
                else if (Input.GetButtonDown("P4"))
                {
                    abCont.RemovePassive(3);
                }
            }
            else if (!abCont.InUse(selectedAb))
            {
                if (Input.GetButton("Upgrade"))
                {
                    if (Input.GetButtonDown("A1"))
                    {
                        abCont.SetUpgrade(abMenuSelected, 0);
                    }
                    else if (Input.GetButtonDown("A2"))
                    {
                        abCont.SetUpgrade(abMenuSelected, 1);
                    }
                    else if (Input.GetButtonDown("A3"))
                    {
                        abCont.SetUpgrade(abMenuSelected, 2);
                    }
                    else if (Input.GetButtonDown("A4"))
                    {
                        abCont.SetUpgrade(abMenuSelected, 3);
                    }
                }
                else if (Input.GetButtonDown("A1"))
                {
                    abCont.SetActive(abMenuSelected, 0);
                }
                else if (Input.GetButtonDown("A2"))
                {
                    abCont.SetActive(abMenuSelected, 1);
                }
                else if (Input.GetButtonDown("A3"))
                {
                    abCont.SetActive(abMenuSelected, 2);
                }
                else if (Input.GetButtonDown("A4"))
                {
                    abCont.SetActive(abMenuSelected, 3);
                }
                else if (Input.GetButtonDown("P1"))
                {
                    abCont.SetPassive(abMenuSelected, 0);
                }
                else if (Input.GetButtonDown("P2"))
                {
                    abCont.SetPassive(abMenuSelected, 1);
                }
                else if (Input.GetButtonDown("P3"))
                {
                    abCont.SetPassive(abMenuSelected, 2);
                }
                else if (Input.GetButtonDown("P4"))
                {
                    abCont.SetPassive(abMenuSelected, 3);
                }
            }
        }

        if (Input.GetKeyDown("f2"))
        {
            GetAbility((Ability)GameObject.Find("Boulder").GetComponent <ClusterShower>());
        }

        abMenuHeight = (numAbilities / abMenuRowSize + 1) * iconSize
                       + (Mathf.Ceil(numAbilities / abMenuRowSize) + 2) * iconMargin;
    }