How to know when TouchScreenButton is pressed?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rz

So i have a game, and in it there is a touchscreen button, i dont know how to know if the touch screen button has been pressed?

heres my code:

extends TouchScreenButton

var motion = Vector2()
func _physics_process(_delta):
	if (is_pressed()):


its not printing when i touch it in run.

That should work, are you sure your identation is correct? Because on the code sample you posted it’s wrong.

Also, are you running this on your computer or on an actual phone? Because clicking a touchscreen button with a mouse won’t press it. You’ll need to go into project settings and enable emulate touch from mouse.

exuin | 2021-04-25 17:08

Nevermind, i figured out that in the action property of touchscreenbutton, i can set an input to trigger, and from a script i can check if the input has been triggered and do something. also i did put emulate touch from mouse.

rz | 2021-04-25 20:03

Oh alright then!

exuin | 2021-04-25 20:15