Guest User

Untitled

a guest
Oct 31st, 2023
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extends Button
  2. export var action: String
  3.  
  4. var _touch_index : int = -1
  5.  
  6.  
  7. func _unhandled_input(event: InputEvent) -> void:
  8.     if event is InputEventScreenTouch:
  9.         if event.pressed:
  10.             if _is_point_inside_area(event.position) and _touch_index == -1:
  11.                 _touch_index = event.index
  12.                 get_tree().set_input_as_handled()
  13.                 Input.action_press(action)
  14.         elif event.index == _touch_index:
  15.             Input.action_release(action)
  16.             _reset()
  17.             get_tree().set_input_as_handled()
  18.  
  19.  
  20. func _is_point_inside_area(point: Vector2) -> bool:
  21.     var x: bool = point.x >= rect_global_position.x and point.x <= rect_global_position.x + (rect_size.x * get_global_transform_with_canvas().get_scale().x)
  22.     var y: bool = point.y >= rect_global_position.y and point.y <= rect_global_position.y + (rect_size.y * get_global_transform_with_canvas().get_scale().y)
  23.     return x and y
  24.  
  25.  
  26. func _reset():
  27.     _touch_index = -1
Advertisement
Add Comment
Please, Sign In to add comment