- Home /
Trigger for reloading level won't work!
I have spent 4 hours trying to see what was wrong. No errors at all. The script is about using a object as a trigger when the player goes in it. I am using a box collider and a character controller. when the player falls into the trigger it restarts the level, but it's no doing it. The script(JavaScript):
#pragma strict
var Player : GameObject;
function OnTriggerEnter (other : Collider) {
Application.LoadLevel(0); //or whatever number your scene is
}
Please give me the ENTIRE code, I never get what your talking about when you just put up a incomplete code. This is for my 2D game.
Try this :
1) You might need to use OnTriggerEnter2D
2) You have no check for if the collision is "Player", this will not stop it working but will mean it works with any object that enters...
3) When you do add a "Player" check make sure you have tagged your player as "Player"
I think Player is a reserved word
EDIT: Well, he may work on a 2.5D game, because he uses the Character Controller
True, but it is worth a try, the player var is never used so that is certainly not the reason why it is not loading the next level. But putting a Debug.Log in this like you said is a good idea. That will say weather or not it is the type of collision statement he has used that is wrong or the actual load level line. :)
Yes, it's true, that's why I asked him to put a Debug.Log.
Is the code you are posting from the script $$anonymous$$illPlayer.js? If not you have errors in another script.
Also, your debug.log is not complete. Like stated above, put:
Debug.Log("test");
Answer by Vetpetmon · Nov 30, 2014 at 04:42 PM
I found it! here's the code!:
#pragma strict
var player : GameObject;
function OnTriggerEnter(other : Collider) {
Debug.Log("Test") ;
Application.LoadLevel(0);
}
LOL, I had to label the both the objects player! I had completely cracked up when I found out! thanks for helping me! You can use this code if you want.
Hmm... strange! It dosn't matter in your code what tag the objects have
I think he is talking about layer? The two objects will not trigger if they are not set up correctly in the physics matrix
Thanks b1gry4n(+1), confusion had taken a firm hold upon my $$anonymous$$d :D
Your answer
Follow this Question
Related Questions
Colliders not working 1 Answer
Assets won't load 0 Answers
XML loading not working for built game 2 Answers