Skip to content

Commit

Permalink
Fixed NPE (Old Reference) after leaving a game and re-joining
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDeadSnake committed Dec 12, 2023
1 parent 2c6a925 commit d9e1f85
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ScreenScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class ScreenScript : MonoBehaviour {
private bool _lookingAtMonitor = false;
private InputAction _primary;
private InputAction _secondary;
private Action<InputAction.CallbackContext> _primaryAction;
private Action<InputAction.CallbackContext> _secondaryAction;

private Bounds GetBounds() {
// Magic values are the offset from the monitor object center
Expand Down Expand Up @@ -130,25 +132,30 @@ 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
Plugin.LOGGER.LogInfo("Set primary button to: " + GetButtonDescription(_primary));
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)) {
Expand Down

0 comments on commit d9e1f85

Please sign in to comment.