Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount == 1)
        {
            //On récupère le mouvement
            Touch t = Input.GetTouch(0);

            switch (t.phase)
            {
            //Commence à toucher l'écran
            case TouchPhase.Began:
                startPosition = t.position;

                //Double tap
                if (t.deltaTime > 0 && t.deltaTime < MaxTimeWait && t.deltaPosition.magnitude < VariancePosition)
                {
                    //Répulsion si cooldown
                    control.Slide();
                }
                break;

            //En train de swiper
            case TouchPhase.Moved:
                if (isSliding)
                {
                    break;
                }
                direction = t.position - startPosition;

                //Déplacement horizontal
                if (Mathf.Abs(direction.x) > threshold)
                {
                    isSliding = true;
                    if (direction.x < 0)
                    {
                        //Aller à gauche
                        control.GoLeft();
                    }
                    else
                    {
                        //Aller à droite
                        control.GoRight();
                    }
                }
                //Déplacement vertical
                if (Mathf.Abs(direction.y) > threshold)
                {
                    isSliding = true;
                    if (direction.y < 0)
                    {
                        //Se mettre en boule / se décrocher
                        control.Slide();
                    }
                    else
                    {
                        //Sauter / s'accrocher
                        control.Jump();
                    }
                }
                break;

            //Fin du swipe
            case TouchPhase.Ended:
                isSliding = false;
                lastTouch = Time.time;
                break;
            }
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount == 1)
        {
            // touch start
            Touch t = Input.GetTouch(0);

            switch (t.phase)
            {
            //Commence à toucher l'écran
            case TouchPhase.Began:
                startPosition = t.position;
                startTouching = Time.time;
                break;

            //case TouchPhase.Stationary:
            //    //if (Time.time - startTouching >= timeBeforeTouch)
            //    //{
            //        control.Jump();
            //    //}
            //    break;
            //En train de swiper
            case TouchPhase.Moved:
                if (isSliding)
                {
                    break;
                }
                direction = t.position - startPosition;

                //Déplacement vertical
                if (Mathf.Abs(direction.y) > threshold)
                {
                    isSliding = true;
                    if (direction.y < 0)
                    {
                        //Se mettre en boule / se décrocher
                        control.Slide();
                    }
                    else
                    {
                        //Sauter / s'accrocher
                        control.Jump();
                    }
                }
                else if (Mathf.Abs(direction.x) > threshold)     //Déplacement horizontal
                {
                    isSliding = true;
                    //if (direction.x < 0)
                    //{
                    //    //Aller à gauche
                    //    control.GoLeft();
                    //}
                    if (direction.x > 0)
                    {
                        //Aller à droite
                        control.GoRight();
                    }
                }

                break;

            //Fin du swipe
            case TouchPhase.Ended:
                isSliding = false;
                lastTouch = Time.time;
                break;
            }
        }
    }