Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question about inputs

Discussion in '2D' started by nuclearsquiddy, Mar 3, 2020.

  1. nuclearsquiddy

    nuclearsquiddy

    Joined:
    Feb 11, 2020
    Posts:
    17
    In my 2D game, I want to make it so that if you press A or D twice, you dash instead of running. So far, I don't know how I can program my game to read 2 key inputs in a certain timeframe. Some guidance would be welcome.
     
  2. Nyfirex

    Nyfirex

    Joined:
    Jun 26, 2019
    Posts:
    179
    Code (CSharp):
    1. if (Input.GetButtonDown("D")){
    2.  
    3.             if (Time.time - lastTapTimeRight < tapSpeed) {
    4.  
    5.                 //Dash
    6.  
    7.             }
    8.  
    9.             lastTapTimeRight = Time.time;
    10.  
    11.         }
     
  3. nuclearsquiddy

    nuclearsquiddy

    Joined:
    Feb 11, 2020
    Posts:
    17
    Thanks, I'll try it soon.
     
  4. nuclearsquiddy

    nuclearsquiddy

    Joined:
    Feb 11, 2020
    Posts:
    17
    tapSpeed and lastTapTimeRight are not used in context.
    I'm assuming tapSpeed is a public float I can change to create a window for the input.
    for lastTapTimeRight I'm just confused. Maybe it's a float, but I'm not sure how to calculate it, since it's the time since the last input was made.
    help...

    Edit: Nevermind, turns out I'm really stupid
     
    Last edited: Mar 4, 2020