hurrmmm/godot/mouse_control.gd

24 lines
534 B
GDScript3
Raw Normal View History

2023-11-11 16:12:46 -07:00
extends Node
func lock_mouse():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func unlock_mouse():
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
func toggle_mouse_lock():
if mouse_is_locked():
unlock_mouse()
else:
lock_mouse()
func mouse_is_locked():
return Input.mouse_mode == Input.MOUSE_MODE_CAPTURED
func _unhandled_input(event):
2023-11-11 16:12:46 -07:00
if event.is_action("charge") and Input.mouse_mode != Input.MOUSE_MODE_CAPTURED:
lock_mouse()
get_viewport().set_input_as_handled()
if event.is_action("ui_cancel"):
unlock_mouse()