top of page

Code Examples

These are a couple of example codes I used for the creation of the game! I also included some information on the code examples given!

Camera Script


This is the current script for the player's ship. This is actually the 2nd variation of the script used for the camera of the ship controlled by the player. 

It originally started as just a basic folow script, but after some play testing (and feedback during my Studio class), I had to revamp it.

This code variation allows for smooth following of the player's ship while also allow for dampening settings. This allows for a slight "lag" in movement of the camera (the Mathf.LerpAngle part of this code to be exact). There is also a Lerp applied to the height attribute that also dampens the Y-Axis movement.

Ship Chooser Script


This was the script that I used to create the ability to choose the ships and the mechanics to play with. 

 

There was a slight issue I had as it pertained to the attributes for the ships. After some digging around, I ran into someone using C#'s Linq (Language-Intergrated Query) library to help easily sort something within his game.

 

After doing some research on Linq, I came to understand that it is actually an awesome way to modify Lists/Arrays (which, outside of SQL queries, is the other nice byproduct of Linq). 

Needless to say, I used the OrderBy function to easily Linear Sort the array, this allowed to have  the correct sprite to be sorted 0-9. 

Scene Manager

 

This script sort of came out as a necessity. I had set up pretty much everything, but I needed a good way to handle player deaths. That was the reason for the creation of this script.

The first part of this script is to actually handle the spawning of the player's ship. This is through the use of Unity's PlayerPrefs feature. It will get the number of the ship choice. Then it spawns the correct ship and despawns the ships not needed. 

This script will take the values of the updated UI's Shield Slider values and proceed to destroy the ship. It also uses Unity's InvokeRepeat method to reload the level (where it, again spawns in the correct ship).

bottom of page