Day 5 — Creating the building blocks for our player
Hey and Welcome!
Now we’re going to get something functioning in Unity and something we’ll be able to move about in our game view which is going to be our player object, or at least the mechanics for our player as they’re looking awfully cubish currently:
Which is where we’re beginning things, to have you’re very own player cube you’ll need to right click in the hierarchy and choose the 3D Object > Cube option. You can also create one from GameObject > 3D Object > Cube from the toolbar at the top of Unity.
Cube doesn’t make for a very good name for our player object though so we’ll want to change that so it makes our life easier when finding and referencing the player from within scripts. Luckily that can easily be done at the top of the inspector window as seen in the left here when you click on your cube object in the scene view or hierarchy. You’ll also want to make sure that you change the tag of your player from Untagged to Player as it will be needed for later when we start getting into collisions.
Next we’ll go about changing the colour as we’ll be adding some enemy cubes later and we’ll need a visual cue to distinguish between the player and the enemy. Create a materials folder in your assets folder in the project window and right click in the new folder then choose Create > Material and name it something along the lines of Player_mat. It’s not necessary to have mat in the name but you’ll want something in common in the name for all of your materials so that it’s easy to search from them.
When you click on the material you’ve created you’ll see the option to change its colour in the inspector window, I’ve chosen the best colour hot pink for mine. Then you can just drag and drop your material onto your player in the hierarchy or in the players inspector window and you’ll now have a colourful looking cube, pretty fun stuff eh?
Lastly before we start on our player script lets change the background to a solid colour by selecting the Main Camera in the hierarchy and then swtiching the Clear Flags option from Skybox to Solid Colour and then choosing a colour of your liking.
You should have something looking like this now. With that sorted it’s time to make a script for our player and start coding in some movement behaviour.
Back in your project window create a Scripts folder in Assets and then right click Create > C# Script and call it Player. Make sure that you name it while it’s still highlighted upon creation otherwise you’ll have to manually change the class name in the script.
That’s all for now with this, we’ll get our player moving in the next one.