- Home /
How can i trigger death , set spawnpoints & add music? ( 2D )
Hey there im new to unity and this is my first project i would really appreciate it if you could help me out with some of your knowledge on how to trigger death ( i want my character to die once he fails a jump ) , how to set spawnpoints & checkpoints and how to add music. Thanks in advance!
Answer by GrayMatterTutorials · Jan 09, 2017 at 08:09 AM
@iTzWaRzZ , a lot of this can be found on YouTube and I actually recommend looking these up individually. They will be able to demonstrate it to you better than I could explain it through text. However, I will say that with triggering the death, you will need to have a controller that watches for the specific condition you want him to fail at, and if he does, then call a method that kills him. So for instance, you want to isolate the deterministic values that determines a failed jump. Maybe it's too low of a score, or the y value is to low... When whatever variable you are looking for fails to meet your requirement, you need to call a method to kill the player. This answer can't be found because there's no way to determine what you consider a "failed jump". As far as spawn points go, I recommend storing empty game objects into a public array on a controller object. The checkpoints really don't matter if their positions are known, we just care what the current one is. I recommend having a collider set to trigger so you can call OnTriggerEnter and if the player enters it, it sets the Controller's Checkpoint value to itself. So if the player dies, you can have it spawn at the Controller.Checkpoint. Lastly, music is something you will want to look up as a video just to explain it a little better. Here's a video that demonstrates both sound effects and background music: https://www.youtube.com/watch?v=O3q0_IkeMDU. Best of luck, and if you have questions, feel free to leave a comment.
Your answer
![](https://koobas.hobune.stream/wayback/20220612104303im_/https://answers.unity.com/themes/thub/images/avi.jpg)