@@ -23,12 +23,20 @@ private void Awake()
2323 _navigateAction = InputSystem . actions . FindAction ( "Navigate" ) ;
2424 _submitAction = InputSystem . actions . FindAction ( "Submit" ) ;
2525
26- // Subscribe to the performed callback only
26+ // Subscribe to input events
27+ _navigateAction . performed += OnNavigatePerformed ;
2728 _submitAction . performed += OnSubmitPerformed ;
2829
2930 _tryAgainHighlighter = tryAgainButton . GetComponent < Highlighter > ( ) ;
3031 _quitHighlighter = quitButton . GetComponent < Highlighter > ( ) ;
3132 }
33+
34+ private void OnDestroy ( )
35+ {
36+ // Unsubscribe from input events
37+ _navigateAction . performed -= OnNavigatePerformed ;
38+ _submitAction . performed -= OnSubmitPerformed ;
39+ }
3240
3341 private void OnSubmitPerformed ( InputAction . CallbackContext context )
3442 {
@@ -37,10 +45,14 @@ private void OnSubmitPerformed(InputAction.CallbackContext context)
3745 return ;
3846 }
3947
40- _highlightedButton ? . GetComponent < Button > ( ) . onClick . Invoke ( ) ;
48+ // Only invoke if the highlighted button is actually active
49+ if ( _highlightedButton != null && _highlightedButton . activeSelf )
50+ {
51+ _highlightedButton . GetComponent < Button > ( ) . onClick . Invoke ( ) ;
52+ }
4153 }
4254
43- public void OnNavigate ( )
55+ private void OnNavigatePerformed ( InputAction . CallbackContext context )
4456 {
4557 if ( ! gameObject . activeSelf )
4658 {
@@ -52,12 +64,7 @@ public void OnNavigate()
5264 return ;
5365 }
5466
55- if ( ! _navigateAction . WasPressedThisFrame ( ) )
56- {
57- return ;
58- }
59-
60- var direction = _navigateAction . ReadValue < Vector2 > ( ) ;
67+ var direction = context . ReadValue < Vector2 > ( ) ;
6168
6269 // Simple navigation between try again and quit buttons
6370 if ( _highlightedButton == null )
@@ -92,5 +99,12 @@ public void SetHighlightedButton(Highlighter highlighted)
9299 highlighted . Highlight ( ) ;
93100 _highlightedButton = highlighted . gameObject ;
94101 }
102+
103+ public void ClearHighlightedButton ( )
104+ {
105+ _tryAgainHighlighter . Highlight ( false ) ;
106+ _quitHighlighter . Highlight ( false ) ;
107+ _highlightedButton = null ;
108+ }
95109 }
96110}
0 commit comments