Search Unity

Question Character movement each button tap

Discussion in '2D' started by dharmesh_b, Sep 3, 2020.

  1. dharmesh_b

    dharmesh_b

    Joined:
    Aug 15, 2020
    Posts:
    8
    Hi Guys,

    I'm new to unity. I wanted to know how to move the character by each tap. For example as you can see the below image. In "a" dashboard if I press or hold the left button character moves instantly to different lane.

    But all I want is "b" dashboard, if I tap left once the character should sweep to next left lane, again if I press the left button the character need to sweep left to next left lane. So user should tap the button each time to shift the lane.

    If anyone can help. I need a script for "b" dashboard type, additionally with timedelta, speed, x axis and with limited space like within box collider of the lanes. Or any tutorial for the same please do let me know.

    Screenshot 2020-09-03 at 5.58.18 PM.png
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @dharmesh_b

    I don't see how this is related to 2D features... you should ask this in scripting forum instead.

    But how to do this... detect your button or key press, then move to target position. This could be done using lerp or move position. Read more about those. When the object has reached its target position, then it can take new input.

    If you are using keyboard Use GetKeyDown instead of GetKey to only detect button down frame and not continuous press. UI has similar events, those work with touch too but you could also use the Touch class if you need more touch specific features.