Here I have a basic menu script which toggles my menu via “tab”. I want to disable the player controller script I have (Named PlayerController) so that I dont continue to move around and play while the menu is up. I tried to do this via accessing the script PlayerController and setting it as “lockkeys”, then using lockkeys to disable and enable it under the “tab” press functionality. It doesn’t seem to work. Is there a better way to do this, or am I doing something wrong?
public class openmenu : MonoBehaviour {
public PlayerController lockkeys;
public Canvas IngameOption;
private bool menuEnabled = false; // call this whatever you wan
// Use this for initialization
void Start ()
{
IngameOption = IngameOption.GetComponent<Canvas>();
menuEnabled = false;
IngameOption.enabled = menuEnabled;
lockkeys = GetComponent<PlayerController> ();
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown("tab"))
{
menuEnabled = !menuEnabled;
IngameOption.enabled = menuEnabled;
lockkeys.enabled = !lockkeys.enabled;
}
}
}