I have tried many ways for my code to work and it is honestly a headache at this point any new codes or issues to fix my code would be extremely helpful. I have no idea what is wrong with my code but it is not working almost at all and yes I have everything set up in unity for it to work I believe it is with this code or the sample code Unity uses for my player controller. Here is the code thanks in advance for the help if you do try to help <3
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Pause : MonoBehaviour {
public static bool gameIsPaused = true;
public KeyCode pause;
public m_MoveDir PlayerMove;
public GameObject pauseMenuUI;
public class m_MoveDir
{
internal bool enabled;
}
private void Start()
{
pauseMenuUI.SetActive(false);
if(SceneManager.GetActiveScene() != SceneManager.GetSceneByName("menu"))
{
PlayerMove = GameObject.FindGameObjectWithTag("Player 1").GetComponent<m_MoveDir>
();
}
}
private void Update()
{
StartCoroutine(Wait());
}
IEnumerator Wait()
{
if(Input.GetKey(pause))
{
if (gameIsPaused)
{
yield return new WaitForSeconds(1 / 4);
Resume();
}
else if(!gameIsPaused)
{
yield return new WaitForSeconds(1 / 4);
Resume();
}
}
}
public void Resume ()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
gameIsPaused = false;
PlayerMove.enabled = true;
}
void DoPause ()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
gameIsPaused = true;
PlayerMove.enabled = true;
}
public void LoadMenu()
{
SceneManager.LoadScene("menu", LoadSceneMode.Single);
if (gameIsPaused)
if(gameIsPaused)
{
pauseMenuUI.SetActive(false);
gameIsPaused = false;
Application.Quit();
SceneManager.LoadScene("menu");
Time.timeScale = 1f;
PlayerMove.enabled = true;
}
}
}