6. User interface objects and memory leaks.
User interface consist of:
- player icon
- health bar
- two icons of weapon
- number of ammunition available
- score
All those elements are represented by objects GUI Texture and GUI Text. Each object has attached script to set optimal position on screen relying on current screen resolution e.g. transform.position = new Vector3(posX, posY, 1); where posX = 0.4f, posY = 0.03f.
Main menu of the game can be recalled by pressing "Esc" key and consists of three options "Resume", "Restart" and "Quit". When "Esc" key is pressed game time is stopped and position of menu is changed to centre of the screen . Menu is drawn on GUI whole time but in different positions. When we want to access the game menu then it position is set to centre of the screen, when we want to close it, its sets it position outside of the screen. If we press "Resume" button, game time is set back to one: Time.timeScale = 1;. For "Restart" option, when the button is pressed, I load scene one and reset global game variables e.g. Application.LoadLevel(1);. For "Quit" option I'm using: Application.Quit(); which will close the game. Last element placed on GUI is screen frame which is a PNG file scaled and position exactly in the centre of screen.
As I progressed with my game I noticed that when the game is running it's constantly consuming computers memory (RAM) until it's full and computer crashed. To fix that I used: Resources.UnloadUnusedAssets(); and I placed it in Update() function.
Game menu:
Screen shoot of my user interface and frame:
No comments:
Post a Comment