A step-by-step log of how I made a basic Unity/C# game: “Slash’n’crack”!
This article is also available on Medium.
The last two weeks, I’ve started to post a bunch of gamedev logs in which I discuss how I’m currently creating a simple Unity/C# mobile game: Slash’n’crack!
For this dev challenge, I have a tight time constraint: I only have 8 hours to make the entire game, from start to finish!
So far, I’ve prepared all of my core features and, last time, I even set up a multi-scene workflow to give the player a smoother experience with a main menu and nice fading transitions to the game scene:
During hour 7, I’ll work on various miscellaneous features and improvements such as additional UI elements in the menu and the game scenes, or asteroid levels.
Hour #7: Adding asteroid levels, improving the main menu, creating a pause panel…
Features & demo
In this episode, I’ll be adding the following features:
- asteroid levels: rather than having all auto-generated asteroid be equivalent, I want some to be “harder” to crack; so I’ll define 3 levels for my asteroids that are shown via its colour and that determine how many slashes it takes before splitting apart:
These levels also set how many points the asteroids give you: 1 for the whites, 2 for the blues and 3 for the reds 🙂
- title and logo: in the main menu, I want to show the title and logo of Slash’n’crack to show something sparkly to the player when he or she first arrives!
- how-to-play panel: in the main menu, I also want to help the players by giving them some guidance if need be, with some basic texts and images of the games and a quick recap of the rules
- pause panel: in my game scene, I want to be able to click a little “pause” button somewhere in my UI to temporarily freeze the game and either return to the main menu or resume
- intro text: finally, at the very beginning of a new game session, I’ll remind the player the goal by flashing a little “Slash the asteroids!” instruction for a brief moment
That’s quite a lot but it’s mainly a repetition of things I did previously… so after an hour of dev, here is the new state of the game!
And with that various additions, all the visuals and main logic of my Slash’n’crack mobile app are finished and I’m done with the core features 🙂
For the final hour, I will add a last “crucial secondary thing” to my game: the audio! So I’ll implement basic retro sounds and musics and I’ll re-integrate my “mute” player preferences logic from The Escape so that I can easily auto-load the mute settings of the players when they re-launch the game.
A few details, tips & tricks
The “How To Play” panel is a simple vertical layout with a Content Size Fitter component to quickly stack my texts and images one below the other.
For the logo and title in the main menu, as you can see, I’ve added a little UI animation to both the images and the texts to make it more appealing to the player! So when you first arrive in the main menu, the logo and text (and their small shadow elements) all “bounce out” from a scale of 0 to a scale of 1. This “bouncing” is done using an easing function inside of a C# coroutine.
Basically, I have a coroutine to play my animation in parallel of the main thread and, inside of this coroutine, I update a timer to go from 0 to my animation length (here, 2 seconds). Every time I update this timer, I also update the scale of one of my UI elements (either the logo, the logo shadow, the title or the title shadow) by normalising this timer and passing it to my C# implementation of the “bounce out” easing function, based on the
I’ve also used a coroutine for my intro text in the game scene so that it pops after half a second, stays visible for 2 seconds and then disappears again.
The pause panel is organised exactly like the “How To Play” panel and it is triggered by clicking the button in the top-right; whenever it is enabled, I also freeze the game by setting the
Time.timeScale to 0, which I can then reset to 1 when I resume the game.
Finally, I now store the level of each asteroid upon initialisation (i.e. when it is spawned by the game manager) to know how many “hitpoints” it has – these hitpoints are then checked whenever I slash it:
- if the asteroid still has remaining hitpoints, it is scaled down and takes 1 hit
- else, it is destroyed and plays the nice “splitting” animation I prepared earlier
I also set the colour of the asteroid when I initialise it so that the player instantly knows the level of the obstacle when it pops in the screen.
Even if I’m about to finish my first prototype of Slash’n’crack, I plan on keeping this game in the back of my mind, and I might get back to it in the future if I get new ideas or want to try things on a basic Android app… and, of course, I’d be really happy if you’d participate, too, so feel free to leave comments with cool features for the v2 of Slash’n’crack 🙂
I hope you like this series of Gamedev Logs, and see you on Wednesday for the last one!