Search Unity

touch input (combine touches)

Discussion in 'Scripting' started by beltmanmarc, Mar 1, 2015.

  1. beltmanmarc

    beltmanmarc

    Joined:
    Aug 19, 2012
    Posts:
    8
    Hello, i made function to handle input for my player for android tablet (see below).
    It works but it is not possible to jump during the horizontal displacement.
    In other words i can not combine touches.
    How can fix this?


    private void HandleInput()
    {
    if (Input.touchCount > 0) // is screen being touched
    {
    Touch t = Input.GetTouch(0); // Get the touch info

    if (t.phase == TouchPhase.Began) // Did the touch begin?
    {
    if (guiRight.HitTest(t.position, Camera.main)) // touching right?
    {
    _normalizedHorizontalSpeed = 1; // player to right
    if (!_isFacingRight) // if player not facing right
    Flip(); // turn player
    }
    else if (guiLeft.HitTest(t.position, Camera.main)) // touching left? {
    _normalizedHorizontalSpeed = -1; // player to left
    if (_isFacingRight) // if player facing
    Flip(); // turn player
    }
    else // no touch
    {
    _normalizedHorizontalSpeed = 0; // no movement
    }

    if (_controller.CanJump && guiJump.HitTest(t.position, Camera.main)) // touching jump?
    {
    _controller.Jump(); // player jump
    }
    }
    if (t.phase == TouchPhase.Ended) // Did the touch end?
    {
    _normalizedHorizontalSpeed = 0;
    }
    }
     
  2. beltmanmarc

    beltmanmarc

    Joined:
    Aug 19, 2012
    Posts:
    8
    in atachement the code more clearer
     

    Attached Files:

  3. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741