0

Disabling Unity Mobile UI Controls during game pause

I've been working on a mobile Galaxy shooter 2D game in unity and it's pretty much finished just a bug I want to fix before publishing. The fire UI button is still active during the pause state of the game. Everything else freezes but the button still works during paused causing an unlimited firing glitch. Anyone have any tips or experience on how to disable the UI buttons actions during the paused state?

8th Jul 2018, 6:53 PM
D Murry
D Murry - avatar
1 Réponse
0
using UnityEngine; using UnityEngine.UI; public class YourScript : MonoBehaviour { public Button fireButton; // Reference to your UI fire button private bool isPaused = false; private void Start() { // Add an onClick listener to your button fireButton.onClick.AddListener(OnFireButtonClick); } private void OnFireButtonClick() { // Check if the game is not paused before allowing firing if (!isPaused) { // Add your firing logic here // For example, you can call a Fire() function from your game logic // Fire(); } } private void Update() { // Check for pause input (e.g., a pause button press) if (Input.GetKeyDown(KeyCode.P)) // Change this to your desired pause input { isPaused = !isPaused; // Disable or enable the button based on the pause state fireButton.interactable = !isPaused; // Pause or resume your game logi
30th Sep 2023, 7:08 PM
D1M3
D1M3 - avatar