Help with Pause Menu needed

Guys, I am new to Unity, have no background in coding whatsoever, and am trying to make an RPG game.

I was wondering if anyone could tell me if, there was a way of reducing my character’s speed (referencing the float thingy from the character controller script to the pause menu script) so that he isn’t able to move at all when I press the pause button. And when I resume again, the speed goes back to being normal.

Thanks in advance!

P.S. let me know if you guys want to have a look at my character controller script if you need more context or something. It would really help me out.

I know new game programmers hate hearing this, lord knows I did, but I’d start with a simpler game first.
Try and make Pong, Flappy Bird, and a simple Mario clone with one level.

If you can’t make these now, then you are doomed to struggle with your current project.

After you have made these little games you should have a much better understanding of how Unity works, how code works, and you will have a lot more confidence.

But to answer your question in a way that will help you understand how this all works.

My first reaction would be to create a bool called paused, go into the Character Controller and find out where it is checking for Key and Mouse Input.
I’d put all that code in it’s own Method, called GetInput().
Then the first line of this method would be.
if (paused) { return; }
this will simply return out of the method before any of the code is run is paused is true.

The idea being, the code that gets the key and mouse input is simply not run while paused is true, so your character cannot move.

This answer itself won’t help you much as you probably have gravity that is not affected by key and mouse input, any enemies will not stop moving while paused, and a slew of other things.

So this isn’t really a direct answer, but more of a theoretical one.

I’m looking forward to seeing your Pong, Flappy Bird, or Mario Clones!
Message me if you want when you make them. :slight_smile:
You can do it!

Well, I actually learned how to use unity along with the very basics of csharp by following a 3d hack and slash course. On top of that, the question here would have been the same if he wanted to pause a flappy bird game.
If you want to learn, you can actually start directly with a big project, but if you do, you shouldn’t even try to hope you’ll ever finish the project and release it as a game. You’ll end up getting stuck if your project is too ambitious, yet you’ll still learn a lot.

You can access to the speed of the game itself and set it to 0. In most cases, that will pause the game,including gravity, monsters and the player.

Try setting Time.timeScale to 0, anything that uses Time.deltaTime will be scaled by it.
Then set it back to 1 to unpause.

Your speed value should be “speed * Time.deltaTime” for that to work properly. That will also make your speed not dependent on framerate.

I forgot about TimeScale!
Nice solution friends. :slight_smile: