My goals for this week were to:
- Add kill collision that resets the level
- Make the collectable item the goal
- Add shooting to the enemy
The first thing I did was add some new collision code to the character control script I made.
This makes the level restart whenever the main character runs into either the walls or the enemy.
The next thing that I did was to add some code which makes the collectable code take you to the next level. I don’t currently have a next level, so instead it takes you to the same level, but I definitely added in different code that makes a win state.
Making the enemy shoot took a long time, but I eventually worked it out. Firstly, I made the projectile code that I added to the fire.
After I added the code, I added a collider and a rigidbody, and I made it a prefab so that it would be saved with these settings. I then made the auto fire code so that it would automatically shoot.
This next part took me a long time to work out, because I wasn’t entirely sure where which code needed to be, however I eventually worked out that the auto fire code needed to be attached to the enemy, and that the ‘projectile prefab‘ needed to have a prefab of the projectile in it. This was a really simple fix in hindsight, but at the time I was completely stumped.
I now have an enemy that shoots only to the right. My next step is to add code that makes the enemy shoot in the direction that it is moving, and to add code that toggles the shooting off and on whenever the enemy sees the main character, however this will be in a seperate post because this too was a long and arduous process.