UI Camera Question
I dont understand UI very well. Im getting close to Pre Alpha of my game and id really like to have a pause menu and ive thought of my own UI Pause which switches the main Camera to a second camera with a UI in front of it. But in my main camera i can interfere with the settings which i really dont like cause when im like swinging an axe i hit the music button on the main camera (not in pause menu) and it blast in my ears outa no where,
Id just like to have a good tutorial that will work in unity 5 with out the clicking on stuff in the pause menu on my main camera.Or please give me an explanation on how to fix this. Thanks people of Unity. You are always a big help to answer my questions :)
Answer by lilBernier · Dec 29, 2015 at 05:03 PM
how do I fix the UI so I can't interfere with it inside of two cameras.
Answer by Ninjapro2k_ · Dec 20, 2016 at 08:24 PM
Try adding a bool for your pause menu, that returns true when the player presses pause and false when they press it again. This is what I use for my pause menu
public class gameManager : MonoBehaviour {
bool showMenu = false;
public GameObject pause;
void Start () {
pause.gameObject.SetActive(false);
}
void Update() {
if (Input.GetKeyDown(KeyCode.P) && showMenu == false)
{
Debug.Log("p was pressed");
showMenu = true;
pause.gameObject.SetActive(true);
Time.timeScale = 0;
}
else if (Input.GetKeyDown(KeyCode.P) && showMenu == true)
{
Debug.Log("p was pressed again");
Time.timeScale = 1;
showMenu = false;
pause.gameObject.SetActive(false);
}
}
}
The Pause gameobject is a UI button that takes you to the main menu. Time.timeScale just makes it so it actually stops all everything so the game is really paused.
Hope this helps ^^