diff --git a/ScreenScript.cs b/ScreenScript.cs index 5ba6cf1..8a615fc 100644 --- a/ScreenScript.cs +++ b/ScreenScript.cs @@ -14,6 +14,8 @@ public class ScreenScript : MonoBehaviour { private bool _lookingAtMonitor = false; private InputAction _primary; private InputAction _secondary; + private Action _primaryAction; + private Action _secondaryAction; private Bounds GetBounds() { // Magic values are the offset from the monitor object center @@ -130,18 +132,18 @@ private void OnEnable() { // Create new InputActions _primary = new InputAction( - name:"Touchscreen:Primary", - type:InputActionType.Button, + name: "Touchscreen:Primary", + type: InputActionType.Button, binding: Plugin.CONFIG_PRIMARY.Value ); - _primary.performed += _ => OnPlayerInteraction(false); + _primary.performed += (_primaryAction = (_ => OnPlayerInteraction(false))); _primary.Enable(); _secondary = new InputAction( name: "Touchscreen:Secondary", type: InputActionType.Button, binding: Plugin.CONFIG_SECONDARY.Value ); - _secondary.performed += _ => OnPlayerInteraction(true); + _secondary.performed += (_secondaryAction = (_ => OnPlayerInteraction(true))); _secondary.Enable(); // Log actions to console @@ -149,6 +151,11 @@ private void OnEnable() { Plugin.LOGGER.LogInfo("Set secondary button to: " + GetButtonDescription(_secondary)); } + private void OnDisable() { + _primary.performed -= _primaryAction; + _secondary.performed -= _secondaryAction; + } + private void Update() { PlayerControllerB ply = LOCAL_PLAYER; if (Plugin.IsActive && IsLookingAtMonitor(out Bounds bounds, out Ray lookRay, out Ray camRay)) {