Pause Menu
When I began working on the pause menu, I went in half-blind. I had some experience with menu UI and had made a few menus previously for my own personal projects, but I didn't know how to actually add pause functionality to the game. My goal was to have the whole game freeze while the player was looking through the menu. While trying to figure it out, I vaguely remembered hearing something about a method called Time.timeScale. Upon some further research and testing, I realized that it was a float used to represent the rate at which time passes within the engine environment. I hadn't really considered it before, but it makes sense for there to be a central system for time-keeping within unity, as so many things depend on it. I was some semi-familiar with the UnityEngine.Time, of which .timeScale and .deltaTime are derivative, but I didn't fully grasp the utility it provided. I went on to theorize that manipulating the timeScale value would suffice for a pause function, so I set it to 0 whenever the pause menu was opened. Voila! It worked exactly how I wanted it to. In using this method, I only came across one particular bug. The cause for this bug is still unknown to me, but I was able to find a workaround that fixed it.
The bug was a simple one. While the game was paused, the player could still fire one and only one projectile, which would hang in the air in front of the player. This is due to physics based movement running off of Unity.Time, so by manipulating .timeScale I was effectively able to pause all physics. The part that remains a mystery to me is that I could fire at all while paused, and why I could only fire once. Those two details seem to contradict each other. My best guess is that because my shooting logic runs on a fire delay timer that incorporates Time.deltaTime, that the first shot resets the timer and it never counts down further to be able to fire again. That, and the initial shooting logic used to fire the projectile in the first place runs off the Update function, which interestingly is unaffected by timeScale whatsoever. I believe this is because the Update function is called every frame, which is a frequency tied to the CPU rather than the central UnityEngine.Time.
As for the actual UI elements, the logic is quite straightforward and simple. Clicking a button calls a simple method that activates/deactivates canvases in order to view the desired menu. This could probably have been done more intricately and efficiently, but the way I did it took very little time and functioned perfectly. I often find myself thinking that I could probably accomplish a task in a more sophisticated way, but remind my self to "Keep it simple, stupid". The overall look for the buttons themselves can be credited to Matt. He picked out the color palette and the font, both of which I ripped directly from his main menu buttons. I did this for continuity and for cohesion from one scene to the next. I think it's important to decide on a visual theme for things like UI and to stick to it.
-Griffin
Get Sanguine Falls
Sanguine Falls
Atmospheric FPS with a Night/Day cycle for killing rounds of vampires in a coastal forest town.
Status | Prototype |
Authors | TDMProductions, Saje, Adequate guy |
Genre | Survival, Shooter |
Tags | Atmospheric, Creepy, daynightcycle, First-Person, Horror, roundbased, Singleplayer, Unity |
More posts
- Build 0.1.4 - Sensitivity Bar addedJan 15, 2024
- Matt Ep. 5 - Finishing touches, polish, details, fxJan 12, 2024
- Matt Ep. 2 - Blender/Pro builder Modelling, Environment, Main Menu + DotweenJan 12, 2024
- Matt Ep. 3 - Day/Night Cycle, Round Management, Game FlowJan 12, 2024
- Matt Ep. 4 - AudioManager, SFX, MusicJan 12, 2024
- PlayerController/HealthJan 11, 2024
- Projectile LogicJan 11, 2024
- Shooting FunctionalityJan 11, 2024
- Matt Ep. 1 - Planning, Vision, MVPJan 06, 2024
Leave a comment
Log in with itch.io to leave a comment.