- Home /
Duplicate Question
how to make a player die on collision
I am making a game were the ball is the player and i need to know how to destroy the player when it collides with the wall game object. is there a way to do it.
Answer by Antony-Blackett · May 30, 2011 at 09:04 PM
Look at the OnCollisionEnter() docs. http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html
after reading the docs add this script to your wall objects.
function OnCollisionEnter(Collision collision)
{
if( collision.gameObject.tag == "Player" )
{
Destroy(collision.gameObject);
}
}
so the player is the player and gameobject is the wall?
C#
function OnCollisionEnter(Collision collision)
Javascript
function OnCollisionEnter(collision:Collision)
Answer by smasgames · May 31, 2011 at 10:58 PM
(@iggy and Antony Blackett) shall i put this script in the player or the wall:
function OnCollisionEnter(collision:Collision) { if( collision.gameObject.tag == "Player" ) { Destroy(collision.gameObject); } }
On the wall, because you check if the other gameobject is taggedas Player. However, it would probably be easier to attach it to the player and check for the wall's tag.
Can you please send any video please it's an humble request!
Follow this Question
Related Questions
Player Health 3 Answers
How to make player (sphere) shoot the ball (another sphere)? 2 Answers
Need Help About Health,Damage 1 Answer
collision with wall so player dies 1 Answer
how to make AI reduce PlayerHealth ?? 0 Answers