Unity Top Down Stealth game

I have been working on a top down stealth game created within Unity. This was mostly used to get a better understanding of the coding for the game. I needed to be able to get the character to move, get a goal to move the player into the next level and code the enemy to move in a certain pattern which they would then get out of to chase and shoot at you if you entered their line of sight. For the most part, I have gotten the code finished for the character and the goal; however, the enemy won’t chase the player nor shoot directly at them .

Code shot 1Code shot 2

This is the code for my menu screen. This code can work for all aspects of the menu. Just set this code on a different button and drag the level into the code when editing the level. It also works for when you want to put in credits for the game.

Code shot 3

This is the code for the enemy movement way points. I haven’t gotten to making the enemy rotate to face the direction that they are facing nor target the player yet. It’s important to have the “OnDrawGizmosSelected” code in when selecting the way points so that you can see where it is that the path the enemy will take, otherwise you will struggle due to not knowing if where the enemy will go is the way you want them to go.

Code shot 4

The code above is used to move the character once a button is pressed. You need to have a rigidbody put onto the character but make sure to put the gravity set to zero to stop the player from constantly falling. I had to download a package from my Google shared drive in order to get the code and other stuff such as character sprite which I had changed for my own.

Code shot 5

Finally, this is the code for the projectiles. Like the character movement, I had to download this from the Google shared drive so that I could get the code plus the projectile needed to be a prefab which was why it was necessary. I needed to change the prefab to the sprite that I was going to use.

Top down gameplay

Here is some gameplay from the game that I have developed. I don’t have the code for the enemy to see and target the player so he will only move in a set pattern whilst shooting automatically. Contact with the bullet or the guard will reset the level; whereas, contact with the goal will send the player to the menu screen. I have also coded the menu so that the start button will start  the stage. I needed to rotate the guard so that he was on his side so that he would stand up normally during the game as the code would rotate him anyways making him upside down when walking on the top area.


Top down gameplay


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s