33
44public class MagneticTarget : MonoBehaviour
55{
6- public GameObject hitEffect ; // Particle effect
7- public TextMeshProUGUI gameCompleteText ; // "Game Complete" text
8- public LevelManager levelManager ; // Reference to LevelManager
9- public float delayBeforeEnd = 2f ; // Delay before ending the game
6+ public GameObject hitEffect ; // Particle effect
7+ public GameObject gameCompletePanel ; // Game complete screen
8+ public TextMeshProUGUI gameCompleteText ; // Completion message
9+ public LevelManager levelManager ; // Reference to the LevelManager
10+ public float delayBeforeMessage = 2f ; // Delay before showing the message
1011
11- private bool isGameCompleted = false ; // Prevent multiple triggers
12+ private bool isGameCompleted = false ; // Prevent multiple triggers
1213
1314 private void OnTriggerEnter2D ( Collider2D collision )
1415 {
@@ -17,20 +18,21 @@ private void OnTriggerEnter2D(Collider2D collision)
1718 Debug . Log ( "Magnet Ball Hit the Final Target!" ) ;
1819 isGameCompleted = true ;
1920
21+ // Stop the timer in LevelManager
22+ levelManager . CompleteLevel ( ) ;
23+
2024 // Trigger the particle effect
2125 Instantiate ( hitEffect , transform . position , Quaternion . identity ) ;
2226
23- // Show "Game Complete!" text
24- gameCompleteText . gameObject . SetActive ( true ) ;
25-
26- // End the game after a delay
27- Invoke ( nameof ( EndGame ) , delayBeforeEnd ) ;
27+ // Display "Game Complete!" message after delay
28+ Invoke ( nameof ( ShowEndScreen ) , delayBeforeMessage ) ;
2829 }
2930 }
3031
31- private void EndGame ( )
32+ private void ShowEndScreen ( )
3233 {
33- Debug . Log ( "Game Completed! Exiting..." ) ;
34- Application . Quit ( ) ; // Works only in builds
34+ Debug . Log ( "Congratulations! You Completed the Game!" ) ;
35+ gameCompletePanel . SetActive ( true ) ;
36+ gameCompleteText . text = "Congratulations! You Completed the Game!" ;
3537 }
3638}
0 commit comments