Player setup for Galaxy Invaders game

Rhett Haynes
4 min readJun 1, 2022

Objective: Creating a prototype of the game with the Player having a material color attached to it. Also, changing the background for better visuals, changing the display screen to standard HD, and placing the Player in its starting position in the game.

Let’s create a prototype of our Player by creating a 3D Object->Cube in the Hierarchy.

Created a cube to represent the player.

Then, name the cube Player as we want to have different objects in this prototype without any confusion.

Named the cube Player.

To change the color of the Player cube, create a Material inside the Materials folder. Select the Albedo channel and change the color of the Player to what you prefer, which in this case we selected Blue.

Blue material added to player.

We want to change the background color of the screen so the Player stands out more onscreen. Go to the Main Camera->Camera->Background and change the color to Black.

Background color changed through the Main Camera.

Let’s change the game screen to a size that will be compatible with different HD screens which will be 16:9 as this is the standard high-definition aspect ratio for HD screens.

Aspect ratio changed to 16:9 which is the standard aspect ratio for HDTV.

To give the Player object the ability to perform in the game, we will use code to give the Player behavior characteristics. Inside the Projects folder, create a new folder name Scripts to hold all scripts used in this game. Then inside the Scripts folder, create a new C# scripts name PlayerBehavior to handle the Player’s characteristics. Double-click on the script to open it in whatever editor you will be programming in which in this case will be Visual Studio.

Created a folder named Scripts with a new script for the Player object inside the Projects folder.

Within the PlayerBehavior script, C# and Unity uses 3 elements to create a program. The 1st is Namespace which is simply a collection of classes used to organize and provide separation of codes that are referred to using a chosen prefix on the class name. Examples such as System.Collections and UnityEngine.AI where System and UnityEngine are namespaces, while Collections and AI are the classes themselves.

The 2nd element is the class name itself that the program will be created under which in this case will be the PlayerBehavior class. Attached to it is the 3rd element which is a Unity class name MonoBehaviour. MonoBehaviour has functions assigned to it that allows us to program the Player to work inside the Unity editor properly. PlayerBehavior inherits from MonoBehaviour which means all methods under MonoBehaviour can be used inside the PlayerBehavior class. This inheritance is allowed through the use of the colon placed between the 2 class names. Inside the script, MonoBehaviour assigns the Start() and Update() functions automatically as these 2 functions are the most commonly used in programming objects.

Using the Start() function, we will begin the game with the Player located at the center of the screen at zero on the X and Z axes, but we will place the player lower on the screen at -3 on the Y-axis in this case.

Starting position assigned to the player when the game starts.

Before playing the game, attach the PlayerBehavior script onto the Player game object and press Play. Notice the Player has moved down the screen at -3 on the Y-axis.

Player’s starting position shown in play mode.

--

--