Edit: sorry, i thought you mentionned GUI buttons^^
There are several ways depending on what you want to do with this.
Connect signals button_down
and button_up
, memorize the time it was when it gets down, and when it gets up, do the difference between current time and memorized time:
var _time_when_pushed_down = 0
func _on_Button_button_down():
_time_when_pushed_down = OS.get_ticks_msec()
func _on_Button_button_up():
var duration_pressed = (OS.get_ticks_msec() - _time_when_pushed_down) / 1000.0
Another way is to accumulate delta
while it's pressed:
var _duration_pressed = 0
func _pressed():
# Reset time when it becomes pressed
_duration_pressed = 0
func _process(delta):
if pressed:
_duration_pressed += delta