Coding and Game Development
Play Game
Level 1 Video:
In this video, you can see hitting an obstacle, respawning, and then completing the level.
Notes:
We made a game similar to "Temple Run" for our first game. In our game, the player, a cube, speeds down a road avoiding obstacles. We accomplished this with Unity's physics system, adding a constant force on the player's z-axis. The player can dodge obstacles using A and D or the arrow keys. The player can also speed up or slow down a bit using W and S or the forward and backward arrow keys. The player can also jump using the space bar. However, this makes the player lose a lot of control, which is a risky move.
In order to detect when the player hit an obstacle, we created a prefab for the obstacles and tagged it for easy detection. When the player collides with an obstacle, all of the player's inputs are disabled and a drag force is applied to the cube. We created a finish line that when crossed, would play an animation to show the title screen. We kept track of how far the player has moved with a score script and used it to show the score when you die. The camera was scripted to follow the player and a Game Manager was scripted to monitor aspects of the game. We wrote 8-10 scripts to control the game and a few more to create and control the UI for the game.
For my customizations, I created a custom shader for the effect of the ground. However, this messed with the lighting so I had to make the ground follow the player. This made the obstacles fall before you reached them though so I had to disable physics on the obstacles until the player reached them. I also created a custom extension for buttons to make them move when you moused over the button.
Code snippets
This code is run when the score text should be updated (every frame during the level and once at the end of the level). It first makes sure that the player variable is assigned, and if it isn't, assigns it, and then sets the text to the current score.
This code is on the finish line and is run when an object goes through it. First, it checks to make sure that the object is the player, and then it tells the game manager that the level is complete.
This code is on the player and is run when it hits something. First, it checks to see if it hit an enemy, and then it ends the game.