Hi, i have made a pause menu which slightly works… I want to disable the mouseLook and movement scripts on the player when they do pause… this script is on an object called GameMaster so i am trying to access the player (where these components are…) but when i pause i can still move the camera around, etc…
if (pause == true && networkView.isMine) {
GameObject.FindWithTag("Player").GetComponent<CharacterController>().enabled = false;
GameObject.FindWithTag("Player").GetComponent<MouseLook>().enabled = false;
GameObject.FindWithTag("Player").GetComponent<CharacterMotor>().enabled = false;
}
else if (pause == false && networkView.isMine){
GameObject.FindWithTag("Player").GetComponent<CharacterController>().enabled = true;
GameObject.FindWithTag("Player").GetComponent<MouseLook>().enabled = true;
GameObject.FindWithTag("Player").GetComponent<CharacterMotor>().enabled = true;
}
Yes, there is a better way to do this. I’ve always had a good mind for how to do pause menus easily. One of the simpler ways as far as Unity goes is to create an empty game object called “activestate” for example. In this activestate game object, you can put EVERYTHING that runs your actual game, ex. the player, level, background, environment, etc.
When the player pauses the game, you can disable the entire state of this “activestate” game object and display another game object instead with your pause menu. If you use this method, then instead of tinkering with tons of different things and tags you only have to disable one single game object. When you reactivate it, everything in there should be as is when the state was last active (except objects that use the “awake” functions may need tweaked a bit).
Another kind of trick (although not anywhere nearly as effective) is to manipulate the time. If you programmed your game correctly, most of the actions/movements/physics are multiplied by “Time.DeltaTime” or “Time.Time”. You could maybe modify those values to multiple by 0 when in pause state. Then the game will “freeze” in action. Just another interesting way to go about it. I prefer the previous method I mentioned.