- Home /
How to restart the level upon cantact
Hey, I was trying to figure out how to use a cube at the bottom of the level to kill the "Player" and restart the level. I don't need health points or anything i just want to reload the level when you contact that cube(insta-death).
this is what I tried
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "Deathzone")
{
Application.LoadLevel("mario mock");
}
}
Do I need to add something or start differently? I'm not sure what I need to do :D
How are you moving your player: direct manipulation of the transform, character controller, rigidbody AddForce, other?
Your platform controller is a character controller. See: OnControllerColliderHit().
Hmm so I played with Hit but its still not working for me. I went and put in Transform to detect "what" will trigger it, but it still doesn't work.... here's my new script
var Player : Transform;
function OnControllerColliderHit(hit : ControllerColliderHit){
if(ControllerColliderHit.Player)
{
Application.LoadLevel(0);
}
}
Answer by geroppo · May 05, 2013 at 02:40 AM
what you wrote seems to be correct, did you test it?
Yes I tested it, It does not work for me. Is it ok to be the only thing in the script? Is there something that should go with it? I'm not sure what else to ask cuz it doesn't work for me.
did you test first if the script is detecting collisions correctly ? do you have a collider attached to both the cube and player ? and also, do you have the scene correctly set in the build configuration ?
YEs to collision and colliders for both cube and player, however, maybe my buidl settings are off, is there something i should look for?
well you could check if in file>build settings in your "scenes in build" window you got the correct scene assigned to it, if you do then you could try using its number ins$$anonymous$$d of the name in your code; so ins$$anonymous$$d of Application.LoadLevel("mario mock"); , do Application.LoadLevel(0); or whatever number you got in the settings.
Your answer
Follow this Question
Related Questions
help needed: death on collision, fade then restart 1 Answer
My Player dies only when he wants to?!? 1 Answer
Don't restart music on death 2 Answers
Why isn't my Death Script Working? 3 Answers
Help with player death on collision! 2 Answers