Exemple #1
0
    void Update()
    {
        if (controlsEnabled && isPaused == false)                                    // do not shift if game is paused
        {
            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) // phase limits the shifting only once per touch
            {
                Touch t = Input.GetTouch(0);

                if (t.position.x < (150))                 // touch left side of the screen (150px), heavy
                {
                    if (heavyCircle.activeSelf)
                    {
                        // do nothing
                    }
                    else if (lightCircle.activeSelf)
                    {
                        heavyControl.Enable(lightCircle);
                        lightControl.Disable();
                        GameController.instance.activePlayer = "heavycircle";
                    }
                    else
                    {
                        heavyControl.Enable(square);
                        squareControl.Disable();
                        GameController.instance.activePlayer = "heavycircle";
                    }
                }
                else if (t.position.x > (Screen.width - 150))
                {
                    if (heavyCircle.activeSelf)                     // touch right, light
                    {
                        lightControl.Enable(heavyCircle);
                        heavyControl.Disable();
                        GameController.instance.activePlayer = "lightcircle";
                    }
                    else if (lightCircle.activeSelf)
                    {
                        // do nothing
                    }
                    else
                    {
                        lightControl.Enable(square);
                        squareControl.Disable();
                        GameController.instance.activePlayer = "lightcircle";
                    }
                }
                else
                {
                    if (heavyCircle.activeSelf)                     // touch middle, magnet
                    {
                        squareControl.Enable(heavyCircle);
                        heavyControl.Disable();
                        GameController.instance.activePlayer = "square";
                    }
                    else if (lightCircle.activeSelf)
                    {
                        squareControl.Enable(lightCircle);
                        lightControl.Disable();
                        GameController.instance.activePlayer = "square";
                    }
                    else
                    {
                        // do nothing
                    }
                }
            }
        }         // android controls end

        // computer controls for changing player, comment out if these disturbs android
        if (controlsEnabled && isPaused == false)
        {
            if (Input.GetKey("1"))
            {
                if (square.activeSelf)
                {
                    heavyControl.Enable(square);
                    squareControl.Disable();
                    GameController.instance.activePlayer = "heavycircle";
                }
                else if (lightCircle.activeSelf)
                {
                    heavyControl.Enable(lightCircle);
                    lightControl.Disable();
                    GameController.instance.activePlayer = "heavycircle";
                }
            }
            else if (Input.GetKey("2"))
            {
                if (heavyCircle.activeSelf)
                {
                    squareControl.Enable(heavyCircle);
                    heavyControl.Disable();
                    GameController.instance.activePlayer = "square";
                }
                else if (lightCircle.activeSelf)
                {
                    squareControl.Enable(lightCircle);
                    lightControl.Disable();
                    GameController.instance.activePlayer = "square";
                }
            }
            else if (Input.GetKey("3"))
            {
                if (heavyCircle.activeSelf)
                {
                    lightControl.Enable(heavyCircle);
                    heavyControl.Disable();
                    GameController.instance.activePlayer = "lightcircle";
                }
                else if (square.activeSelf)
                {
                    lightControl.Enable(square);
                    squareControl.Disable();
                    GameController.instance.activePlayer = "lightcircle";
                }
            }
        }         // computer controls end
    }