[GDScript][C#] Double Tap Key

RukiriRukiri Posts: 58Member

Saw this was a common thing asked for, so here's a simple way of doing double taps in C# and GDScript.

GDScript

func _process(delta):
    if (dash_cool_down_u > 0):
        dash_cool_down_u = dash_cool_down_u - 1 * delta
    else:
        dash_button_count_u = 0

func _input(event):
if (event.is_action_pressed("ui_up")):
    if (dash_cool_down_u > 0 && dash_button_count_u == 1): 
        print("double tapped Up")
    else:
        dash_cool_down_u = 0.5
        dash_button_count_u = dash_button_count_u + 1

C#

using Godot;
using System;

public override void _Process(float delta)
{
    if (dash_cool_down_d > 0)
    {
        dash_cool_down_d = dash_cool_down_d - 1 * delta
    }
    else
    {
        dash_button_count_d = 0
    }

}

public override void _Input(event)
{
    if (event.is_action_pressed("ui_down")) 
    {
        if (dash_cool_down_d > 0 && dash_button_count_d == 1)
        { 
            print("double tapped down")
        }
    }
    else
    {
        dash_cool_down_d = 0.5
        dash_button_count_d = dash_button_count_d + 1   
    }
}
Sign In or Register to comment.