24 lines
524 B
GDScript3
24 lines
524 B
GDScript3
|
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 _input(event):
|
||
|
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()
|