- Home /
load level on collision
how can i reload the last level when i collide with the wall
Collision picture: http://2.bp.blogspot.com/-SJx6M6L-f14/TeT5XKrEuPI/AAAAAAAAAAQ/r68csxwh2ik/s1600/Screen+shot+2011-05-31+at+15.09.40.png
at the moment i can't do anything
Is your wall named "wall"? Have you applied the code to the player? The name is just an example, you could also use tags ins$$anonymous$$d (which would be to prefer probably).
Yes it's a game object with cubes that are sized to look like a wall, as the child objects.
Answer by save · May 31, 2011 at 02:35 PM
function OnCollisionEnter (collision : Collision) {
if (collision.gameObject.name=="wall")
Application.loadLevel(Application.loadedLevel);
}
cant get this to work. The script is added to a cube but when the First Person Controller runs into it nothing happens
function OnCollisionEnter (collision : Collision) {
if (collision.gameObject.name=="First Person Controller")
Application.loadLevel(2);
}
For the character controller you would use OnControllerColliderHit().
function OnControllerColliderHit (hit : ControllerColliderHit) {
hit.gameObject.Send$$anonymous$$essage("Collision$$anonymous$$essage", hit.gameObject.GetInstanceID());
}
// The objects to collide with must have receivers:
function Collision$$anonymous$$essage (id) {
if (id == gameObject.GetInstanceID()) {
Application.loadLevel(Application.loadedLevel+1);
}
}
tried figuring this out by myself but couldn't find out what is a receiver and how do i add them
It's just a ter$$anonymous$$ology when sending a message across scripts. Create a new JS file and paste the script from my example and you should be ready to go.
Still cant get it to work I added a debug.log to the OnControllerColliderHit and that never shows up either.
Answer by SakuraHolm3s · Oct 28, 2013 at 10:47 PM
pragma strict
private var NL = false;
function OnControllerColliderHit(hit:ControllerColliderHit) {
if(hit.gameObject.tag == "NextLevel")
{
Debug.Log( hit.gameObject.tag );
yield WaitForSeconds (3);
NL = true;
} }
function LateUpdate() { if(NL) {
Application.LoadLevel(0);
NL=false;
} }
be sure to set the tag right !!! (spelling also) 2: be sure to set the level you want to load to the number 0 in the build settings under file.
but ... you don't need the : yield WaitForSeconds (3);
you can use it if you want it to wait 3 seconds before loading the other level.
found at http://answers.unity3d.com/questions/39961/collision-load-level.html
Your answer
Follow this Question
Related Questions
Load New Scene On Collision. 1 Answer
help with script load level on 0 enemies 2 Answers
On Collision enter the next level? Help please? 2 Answers
Load last scene/level 4 Answers