Today I will be adding a pause mechanic. I made a new public integer named TimeInt. This will switch between 1 and 0. I then added script that changes the integer to 1 if the escape boolean is true, and 0 if it's false. Then I added a final script that sets the TimeScale to be equal to TimeInt every frame.
This will prevent objects in the scene from moving. Afterwards I added this little bit to make the TimeInt variable start at 1, otherwise it would have nothing assigned to it to begin with.
I started running into a problem. Whenever I started the game, my character could move around. that's fine. However, once I pressed escape, it would still be able to move. And if I press escape again to get out of the menu, my character would then freeze. I decided to try using two if statements instead of an if/else.
That still didn't work, so I decided to try switching the values.
And it somehow worked. It doesn't seem like it should work, but oh well. I'll go with it.
Now I need a way to disable turning the camera when in the menu. I simply added a bit of math to the sensitivity for the camera.
This will multiply the sensitivity by whatever value the TimeInt value is. So if the value is 0, then the the camera movement value will be multiplied by 0, stopping it from turning.
Turns out I can't put a "Find" function there. Instead, I made a variable called TimeInt2, and set that equal to TimeInt. Then I used that and multiplied it.
And that still didn't work. So far, nothing I have tried has worked. I think I will leave the mouse movement pausing until later. Next class, I will be adding a health statistic.
No comments:
Post a Comment