Programming Unity C#//

experience in Programming is hard to define in the visual concept perspective.

Unity code will broken down into categories and systems with an explanation.

FYI: This is how I program a game and its contents from start to finish, It's a played out path I have broken down When building games but that being said, This may or may not work for everyone. they can choose their own path differently or come up with a completely different routine entirely.

Game Structure//

  • Game Control Object

The "brain" of the game and controls all objects within the scene, Acts as the control system. In code "Don't Destroy on Load" is called from script which will only be used as a single instance, this allows this object to "transfer" between loading scenes without being removed. Also if another instance of this object would exist would result in the extra object being deleted.

  • Saving & Loading

Saving and loading your game is crucial with most games that need to retain a specific point in your progress.

These methods would be called from the Game Control object at anytime. saving before death, loading after death, keeping progress before a difficult point in the game. Loading may be called upon booting your game or pressing a loading button. Saving can be called upon player request, gradually, or timely.

 

In code An empty player Data class can be created to "store" information about your game. Upon saving Would grab Live Single instance information like health, armor, what weapons are unlocked, what levels are beaten, Scenes and player position in the level and store this information within a save file. In the beginning the Save() method, would create a binary file and save the new information to a "Stream". after all of data was stored, would close the stream and can now be used In Loading. The Load() Method Checks for an existence of a file, open the stream and Set all of the Games live instances to the information stored in the save file.

  • Singletons 

These are variables that only exist as a single instance throughout your code. The Game Control system would use singletons to store important game information. The game control script can contain leader board information, Options, or UI information like your call sign, basically All information that you only need one of in the game.

Game UI Content//

  • Logos and Title Screens

Within the main menu system script would contain the "beginning" of the game. In code would boot a short company introduction and transition into the Games main title screen. Add a Press start input and transition into the main menu itself.

  • Main Menu

Main Menus mostly contain transitioning Code and Switching UI Elements, like buttons, menus, scrolling text. You can use Unity's System.collections API and Call Coroutines to control Fading Menus. Using for/while loops within a IEnumerator method, you can develop a Fading Method Which takes a blacked out UI element and Lerps the Alpha within the color vector as if the game "fades" into a blank screen. You can also use this method to Fade UI images and sprites. This can give you control to load different sections of your game after the object has faded out.

Each section of the main menu would contain what directs your games behavior, Selecting a difficulty, game modes, your options before you start playing the game. The code would contain direction to other containers and enabling/disabling other static variables and objects.

  • Options MEnu

Option Menu Script contains a large amount of Getter and setter methods. These are used for UI elements like buttons, scroll bars, check boxes, But will also hold your games setting information. In code you can detect your pc's resolution, speaker mode, and draw information from your audio mixer in unity to control volume. This also enables the user to set a comfortable player movement sensitivity and adjust in game settings that make the game more accessible or easier to play.

  • Loading screens

This type of system would control the Core Game transitioning. When A game is built with multiple scenes or objects for pooling, this script system would process whats happening in the back ground when the user is waiting for the game to build the games content. This would include loading a new scene altogether or instantiation of hundreds of objects at a time. This can be adjusted to display a loading bar, or a percentage. Create a slideshow while the user waits, some games include mini games, although this is difficult to be taken into account due to the process takes a majority of memory when the game is building the next section. 

Game  Content//

  • Player Controller

This is an important piece of the game, your character. The code to process a player controller can be extremely advanced depending on the detail on what the player does in the game. It's also important to know different ways a player can move, whether it's using unitys Components with Rigidbody using physics based movement or using the Character controller component and move based on move direction. You can also use translation of vectors for a player controller that can  contain all six degrees of freedom, something that isn't grounded like a space ship shooter.

The player controllers complexity broken down can be the basics like movement, jumping, running, looking around etc. but as the script grows it gets more defined, making footstep sounds, shooting a gun, showing a health or stamina bar, having a image to flash on your gun, taking damage. This script will control the utmost important feature of your game, and defines if the user enjoys your game or not.

  • Pause 

Pausing the game its important for unexpected interruptions or break time, Using unity's time scale gives all scriptable objects that use Time.deltaTime to come to a halt or slow down based on time Scale. This is when thew script would either dim the screen and display a text or image showing the game was paused, but more defined games can access a menu which allows the player to go back to options when something feels off, quit the game back to the menu or quit entirely.

Each section of the main menu would contain what directs your games behavior, Selecting a difficulty, game modes, your options before you start playing the game. The code would contain direction to other containers and enabling/disabling other static variables and objects.

  • Game UI

Another important aspect of the game, this can contain some of the players UI factors like a Score, Health, equipped weapons etc. but also for the sake of an RPG you can route and inventory system that the player can interact with to restore lost health, possibly save your game from the Game control. Inventory managed systems can have Click events called from Unity Events API. This helps when having multiple button pressed items and calling methods. These methods would decide what true or false statement would be enabled or setting an array of sprites to one button based on a situation in the game. This can be aided with the use of delegates.

  • Game AI

Ai programming can be tricky at times, getting an object to move on its own in a dynamic or static path. code based, is no different than the player controller. These objects can use some of the same unity components, World to screen point can be used to display a UI object over a 3d object, World To View port Point detects if the object is in front of the camera, AI objects needs to be intractable with the player as well as the environment. State machines are usually the best way to script AI objects by setting "states" that change based on the status of it or player. States can be set up as enums and using switch statements, which are called by selecting the method statement when the status changes in the game. 

  • Level Design

Levels need interact-able objects. this includes moving platforms, allowing the player to climb ladders, open doors. Code can completely revolutionize the world in the game. You can set texture offset to change via code to give textures like "flowing water" a more lively feel. Designing switches to jump on press, to light up the room, or play sounds that add to the game feel. Level design objects are changed via animation and code which designs the layout on how the user "plays" the game.

  • Game Story

Story can be added in a game but it's not mandatory, Game story can include camera angles and movement. When interacting with AI for example a UPC, in code you can design a dialogue system to control the display interaction. a UI banner with text scrolling gives the user to learn more about whats happening in the game through the UPC. This can conjoin with level design when the player interacts with objects to learn more. The story script setup may be broken into other scripts to display game videos or show a preview of the player character talking in the game.

Game  Conclusion//

  • Game Over

Game over systems detect if the player died or finished playing. usually will result in a summary or results of the game progress. This can access the game controls Save and loading Methods on game over, to allow the player to continue playing or give a count down 

© 2020 Michael Wills / N163LPH03N1X Games