- Home /
Answer by Mister-Mortal · Nov 23, 2016 at 08:52 AM
Have a global static boolean. Before any input you could check if it's true or false and easily set it when you want to.
Example of static boolean:
public class GameManager : MonoBehaviour
{
public static bool IsInputEnabled = true;
}
Call it to check if input is enabled:
if(GameManager.IsInputEnabled)
{
if(Input.GetKeyDown("a"))
{
//do stuff
}
...
And when you want to enable or disable input you can do that like this:
if(Input.GetKeyDown("e"))
{
GameManager.IsInputEnabled = false; //disable all inputs
}
thank you very much, this was very helpful, if you could also help me with one more thing, if I wanted to do this to an external script too, how would I do this
You can access static variable from anywhere you want. It's global. In any of your script just write Game$$anonymous$$anager.IsInputEnabled and you will access the variable.
Your answer
Follow this Question
Related Questions
problem whit input key 2 Answers
Key not recognized 2 Answers
Is it possible to change keyboard input inGame 1 Answer
Using Xbox gamepad triggers as keys instead of axis? 1 Answer
Animation End as a trigger and how to disable input 1 Answer