I am having trouble with resuming my game from the ingame menu. I am using a bool to indicate if I am paused or not GameIsPaused and when I set it to false in my resume function it wouldnt resume and the menu would still be there. I had added a check for this bool in the gun shooting script and it seems like that is getting in the way of my resume function. What am I doing wrong here please help!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using StarterAssets;
public class PauseMenu : MonoBehaviour
{
public bool GameIsPaused = false;
public GameObject pauseMenuUI;
public GameObject soundSettingsUI;
private CharacterController _controller;
private StarterAssetsInputs _input;
private void Start()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1;
GameIsPaused = false;
_input = transform.root.GetComponent<StarterAssetsInputs>();
}
private void Update()
{
if (_input.PauseGame)
{
if (!GameIsPaused)
{
Pause();
}
else
{
return;
}
}
}
public void Restart()
{
AkSoundEngine.StopAll();
Time.timeScale = 1;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void soundSettings()
{
soundSettingsUI.SetActive(true);
}
public void soundSettingsClose()
{
soundSettingsUI.SetActive(false);
}
public void Resume()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
pauseMenuUI.SetActive(false);
Time.timeScale = 1;
GameIsPaused = false;
}
public void Pause()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
pauseMenuUI.SetActive(true);
Time.timeScale = 0;
GameIsPaused = true;
}
public void Quit()
{
Application.Quit();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using StarterAssets;
public class Gun_01 : MonoBehaviour
{
private StarterAssetsInputs _input;
[SerializeField] private GameObject _bullet_01;
[SerializeField] private GameObject bulletPointPrim;
[SerializeField] private GameObject bulletPointSec;
[SerializeField] private float bulletSpeedPrim = 600f;
public int _primaryAmmoCount;
public int _secondaryAmmoCount;
private Player_Audio playerAudio;
private Animator _animator;
private PauseMenu menuSystem;
void Start()
{
menuSystem = GetComponentInParent<PauseMenu>();
_animator = GetComponentInParent<Animator>();
_input = transform.root.GetComponent<StarterAssetsInputs>();
}
// Update is called once per frame
void Update()
{
if (menuSystem.GameIsPaused == false)
{
if (_input.ShootPrimary)
{
ShootPrimary();
_input.ShootPrimary = false;
}
if (_input.ShootSecondary)
{
ShootSecondary();
_input.ShootSecondary = false;
}
}
}
void ShootPrimary()
{
_animator.SetTrigger("shootPrimary");
GameObject bullet = Instantiate(_bullet_01, bulletPointPrim.transform.position, transform.rotation);
bullet.GetComponent<Rigidbody>().AddForce(transform.forward * bulletSpeedPrim);
Destroy(bullet, 1);
}
void ShootSecondary()
{
Debug.Log("ShootSecondary!");
}
}