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 Control Object
The "brain" of the game and controls all the main objects of the game menus, player, pools and game objects that carry over through each scene, This 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.
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. Just recently, singletons now remain used only if necessary, where their "global access" can be dangerous so their purpose remains only to access a class instance.
Game UI Content//
Intros, 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 game intro then into the Games main title screen by adding a Press start input and transition into the main menu itself.
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. Though this option is not memory managed if not done correctly. It's best to update this transition as per frame in Update().
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.
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. You can really play with the settings if you add Post Processing in your project, you can add options to enable bloom, chromatic aberration, grain or brightness as well as adjusting their intensity values.
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 what's 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.
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 Unity's Components with Rigid body 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.
Pausing the Game
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 the 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.
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 an 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.
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. Although Unity's Nav mesh agent used for movement, but this can cause issues with player detection, knowing when the chance the player or look for the player if they of off the Nav surface. Using Unity's "New" Nav Mesh Surface component allows for the Static Nav surface be baked on dynamic game objects. Nav Mesh Links give the agent an opportunity to travel of the Nav surface or travel between different surfaces. 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 an enum and using switch statements, which are called by selecting the method statement when the status changes in the game.
Levels need interactable objects, this includes moving platforms, allowing the player to climb ladders, open doors etc. Code can completely revolutionize the world in the game. You can set the material 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.
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 what's 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 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.