- Home /
Help with InstantDeath Collider Script?
Anyway I could make this only kill the player when it collides with the player?
function OnTriggerEnter (col : Collider) { var player : FPSPlayer = col.GetComponent(FPSPlayer);
if (player) { player.ApplyDamage(10000); } else if (col.rigidbody) { Destroy(col.rigidbody.gameObject); } else { Destroy(col.gameObject); } }
function Reset () { if (collider == null) gameObject.AddComponent(BoxCollider); collider.isTrigger = true; }
I wouldn't destroy the player object if I were you. From my so far limited experince in game creation, it seems better to disable the renderer of the player object and any input checking assoicated with the player oject. Otherwise you can end up with null reference exception where something is trying to interact with the destroyed player.
@originalbadboy: This is a good point. Usually a lot of scripts reference the main player, if you destroy it and there aren't checks in all those references to see if the gameObject is null, you will develop problems.
Answer by AnXgotta · Aug 12, 2012 at 05:07 AM
A common way to filter collided objects is with tags. You could assign the player with a tag such as "Player" and then do the check in the OnTriggerEnter function.
function OnTriggerEnter(col : Collider){
if(col.gameObject.tag == "Player"){
//do player death related things
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613075529im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
3D Building Object collider not working 0 Answers
My Player keeps launching into the air 4 Answers
Jet bike is not moving forward. 0 Answers
How to make player go through object but can't go back 3 Answers
Accesing Player colliderhit with other gameobject? 2 Answers