Adding health and second player
The next thing I aimed to accomplish was to add a functioning health bar to the player that would be attached to them and follow them around. This was pretty simple to add and didn't have any problems in adding it. This was until I decided to create a second player by duplicating the first one.
I initially gave player 2 its own tag and colour to set it apart from player 1. I then had to add a function in my script to make horizontal and vertical input variables then switch how they control in the project settings and assign the controls to each player. The main problem came with adding the health bar to the second player.
The initial problem I encountered is that regardless of who got hit only player 1's health would drop. This was a simple fix since it was a case of detecting the collision based on player 2's tag rather than only player 1's. The bigger problem was still figuring out how to get player 2's health bar to act as its rather than staying connected. I decided I had to create a new health variable for player 2 with the same script of the initial variable but only for the tag player 2.
Lastly as a quick edition I made it so when the player dies it loads a random scene so the game can progress. I had to get the current scenes number and use that to make sure it couldn't roll the same scene twice in a row which was easy to implement.
Get Project T
Project T
Status | Released |
Author | NightlyClover2 |
More posts
- Sounds/finishing upJun 10, 2024
- Round system and UIJun 10, 2024
- Bullet reflection and ability 1Jun 08, 2024
- Starting outMay 18, 2024
Leave a comment
Log in with itch.io to leave a comment.