The Update function is running in game test and the Quit function appears to be working also. I cannot get the input to register in game. this script is a component in the UI canvas which is the parent object of the panel which is the parent of two buttons, and some title text. I put the the panel Game object in the Pause Menu UI object reference for the script and I don’t understand why it’s not working. I’m not 100% sure if it is a scripting error or possibly some setting inn the editor I missed. Any help would be largely appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PauseMenu : MonoBehaviour
{
public static bool GameIsPaused = false;
public GameObject pauseMenuUI;
void Update()
{
Debug.Log("Run Update Function");
if (Input.GetKeyDown(KeyCode.Escape))
{
Debug.Log("If Statement Ran");
if (GameIsPaused)
{
Debug.Log("Run Resume if GameIsPaused = true");
Resume();
}
else
{
Debug.Log("Run Pause if GameIsPaused = false");
Pause();
}
}
}
public void Resume()
{
Debug.Log("Run Resume Function");
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
}
public void Pause()
{
Debug.Log("Run Pause Function");
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
}
public void QuitGame()
{
Debug.Log("Quitting game...");
Application.Quit();
}
}
Try changing the KeyCode to something else temporarily. Escape has a special binding already in the Unity editor, so it might not work properly in play mode in the editor.
It should work fine in a build (test it). You can do something like this:
You’ve already put a ton of great Debug.Log() statements in the code (this is EXCELLENT!) and yet you’ve told us nothing about which ones are running! That’s kinda important information.
There’s either a compiler error, a runtime error, or there is no error and you just have a bug.
Do you see errors in the console? If so, read this:
The complete error message contains everything you need to know to fix the error yourself.
The important parts of the error message are:
the description of the error itself (google this; you are NEVER the first one!)
the file it occurred in (critical!)
the line number and character position (the two numbers in parentheses)
also possibly useful is the stack trace (all the lines of text in the lower console window)
Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.
Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
Thank you for your help, it didn’t turn out that there was anything wrong with the code, which I should have anticipated, because it seemed logically sound. As a beginner to Unity, I’m still learning, but it turned out that the player controller settings allow for use of an older input manger, an updated/newer one, or both. I was attempting to use one kind of input management while the setting was of the opposite variety. Changing the player controller settings to use both fixed my problem. Again, thank you very much.
It seems as though I posted in the wrong thread, I was having a rough go at fixing the problem I was having, and wasn’t thinking that since I wasn’t getting any errors, it was probably fine. Even though it seemed an awful lot like you were thrashing me for beginner errors, which I’ve got all of 50 hours at most working with Unity and C#, the information you had given was useful and if I have a legitimate scripting problem, I will certainly make an effort to give everyone the help necessary to help me out.