- Home /
Best practices to listen for inputs and show GUI?
Hello guys. Sorry for including different things like inputs and GUIs in the same question, but i have similar doubts on how to handle them that comes down to design: a centered approach vs local approach.
So, i have configured inputs in Unity's Input Manager (in this case, for Xbox360 gamepads), but i am not sure what's the best way to listen for them in the game. Should i listen for them in a centered way? Like so:
public class GamepadInputManager : MonoBehaviour {
void Update () {
if(Input.GetButton("A")){
Player.jump();
}
if(Input.GetButton("X")){
Player.attack();
}
if(Input.GetButton("Y")){
//Do stuff somewhere...
}
if(Input.GetButton("B")){
//Do stuff somewhere...
}
}
}
The catch is that this script will need lot of references to other scripts, like the Player, so it can call functions from all over based on what the player presses. But it does look pretty clean...
...Or should i just call inputs locally in scripts as needed?
Also, should GUI functions be centered in a similar fashion? As in:
public class GUIManager: MonoBehaviour {
public void showHealthBar(){
//Show stuff...
}
public void showPauseMenu(){
//Show stuff...
}
//Other GUI functions...
}
Or, as with input, should i just create GUI functions in scripts that have something to show?
What are the recommended practices for those situations?
This question is too broad for Answers, there isn't a single, correct answer either. Better to delete the question here and ask again in the Forums.
I'm not so sure. There can be a value to this question here. The question is specific enough I$$anonymous$$O. To answer OPs questions: I generally put input in the specific scripts and I put GUI in one central script.