- Home /
In-game menu screens
Hello, everyone.
Making a small game I got to the point where I want to add menus to my game. I came to conclusion that the main menu should be made in a separate scene and in-game menus - in the gaming scene with the help of Unity.GUI.
The problem here is I don't know how to make GUI work alongside the scripts for my GameObjects. Let's say during the game I move my player/cursor/whatever with gamepad's analog stick. When I hit some very special button - the menu shows up. This menu should be controlled with the same analog stick of the same controller. So I'll have two objects receive input and react to it at the same time, which is not desirable.
For now I have made almost all my scripts inherit from PausableMonoBehaviour which itself inherits a MonoBehaviour and can be paused/unpaused and reacts to it like this:
void Update()
{
if(IsPaused)
{
return;
}
// do the input and other stuff here
}
This one works OK but I wonder if there are better solutions? I thought of FSM's, but can't seem to pack it all up with the component-based programming model.
P.S. By OK I mean for now - while I don't have a lot of objects in my game. Because with all this objects around I have to use FindObjectsOfType() (which is not very fast I believe) and then iterate all found objects to pause them. And then comes UNPAUSE with the same logic! So it seems that this solution is far from perfect.
Answer by whydoidoit · Feb 21, 2014 at 04:59 PM
So it sounds like IsPaused should be a static so you can set it and not have to find any objects.
Guess that should work. Especially since there's only one thread. Thanks.
Your answer