Esempio n. 1
0
    void Update()
    {
        if (isWrong)
        {
            return;
        }
        else
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (isPaused == false)
                {
                    PS.GetComponent <pauseScript> ().PauseGame();
                    isPaused = true;
                }
                else
                {
                    PS.GetComponent <pauseScript> ().PauseGame();
                    isPaused = false;
                }
            }
        }

        if (GameObject.Find("Canvas/ImageTip") != null)
        {
            if ((Input.anyKeyDown) || Time.time >= 7)
            {
                RemoveTip();
            }
        }

        controller.Move((Vector3.forward * speed) * Time.deltaTime);


        if (Time.time - startTime < animationDuration)
        {
            return;
        }

        switch (characterinput)
        {
        case 0:
            controllers.SetActive(true);

            if (Input.GetKeyDown(KeyCode.D))
            {
                if (lane < 3.0f)
                {
                    lane += 3.0f;
                }
            }
            else if (Input.GetKeyDown(KeyCode.A))
            {
                if (lane > -3.0f)
                {
                    lane -= 3.0f;
                }
            }

            if (Input.GetMouseButtonDown(0))
            {
                if (Input.mousePosition.y > Screen.height / 3.5)
                {
                    if (Input.mousePosition.x > Screen.width / 2)
                    {
                        if (lane < 3.0f)
                        {
                            lane += 3.0f;
                        }
                    }
                    else
                    {
                        if (lane > -3.0f)
                        {
                            lane -= 3.0f;
                        }
                    }
                }
            }

            break;

        case 1:

            if (Input.touchCount > 0)
            {
                t = Input.touches[0];

                switch (t.phase)
                {
                case TouchPhase.Began:
                    startPosition = t.position;
                    return;

                case TouchPhase.Ended:
                    Vector3 positionDelta = (Vector3)t.position - startPosition;

                    if (Mathf.Abs(positionDelta.x) > minimumSwipeDistanceX)
                    {
                        if (positionDelta.x > 0)
                        {
                            if (lane < 3.0f)
                            {
                                lane += 3.0f;
                            }
                        }
                        else
                        {
                            if (lane > -3.0f)
                            {
                                lane -= 3.0f;
                            }
                        }
                    }

                    return;

                default:
                    Debug.Log("Swipper no swipping...");
                    return;
                }
            }

            break;

        default:
            Debug.Log("No input has been selected");
            break;
        }

        moveVector         = transform.position;
        moveVector.x       = lane;
        transform.position = moveVector;
    }