- Home /
kill script!
i have been searching around for an hour for a script that kills players on contact for an enemy, but nothing is working. any suggestions>?
Answer by robertbu · Feb 10, 2013 at 08:03 PM
How will depend on the nature of the game and how you've set it up. Typically your player's will have something like:
function OnCollisionEnter(collision : Collision) {
if (collison.collider.tag == "Enemy")
// Do whatever you want to kill player
}
Research OnCollisionEnter(), game tags, and perhaps Destory().
eeveelution8 you will need to look at writing your own player death subroutine. Some measure of health system, and a means of storing those variables. Then you can simply subtract the damage from the HP, check to see if the HP is below 0 (then set it to 0) and then do the whole Handle Death event. There would be a decent amount of coding required.
Code in C# void OnCollisionEnter (Collision collision) { if (collision.collider.tag == "Enemy") { Application.LoadLevel ("LevelOne"); } }
Answer by CreepyCat2 · Apr 13, 2018 at 12:25 AM
level one was my example you can change it as you like who ever is using C# anyways i just accidentally forget to post as a mini post on the other on
Your answer
![](https://koobas.hobune.stream/wayback/20220613092451im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Display var on gui not working... 2 Answers
Script Not counting enemy kills. 1 Answer
If Enemy Health (< 10) then Exp (+10)? 1 Answer
Enemy AI help 1 Answer