Switching Scenes in 2D
Alright so I finally started scripting on my own and people keep telling me this is one of the easier questions, so I have a long road ahead of me. Anyway Im trying to switch scenes in unity 2d
void OnTriggerEnter2D (Collision2D Colider)
{
if(Colider.gameObject.tag == "Player")
Application.LoadLevel(level);
}
this script isn't working because when I hit the object with my player I don't switch scenes, I have the scene in my build, is Trigger is checked and it has a Rigidbody2D
What am I doing wrong? How can I avoid this in the future?
And you are testing it with a Player gameobject whos tag is set to "Player"?
Does this player have collider and non-kinematic rigidbody?
Yes it has a 2D box collider and a non kinematic rigid body but when you mean if the tag is set to "Player" does it have to be in quotes? @meat5000
Good cause its not inside quotes but it still isn't working
Try to set level to an integer which is the level you need to go to. And test again.
Application.LoadLevel(1);
The number can be seen and organized in File> Build Settings> Scenes in build.
If the level you want to load is not in, open the scene with the level and click on Add Current.
Sadly that didn't work but I get this error that says Script error: OnTriggerEnter2D This message parameter has to be of type: Collider2D The message will be ignored.
void OnTriggerEnter2D (Collider2D Colider)
{
if(Colider.gameObject.tag == "Player")
Application.LoadLevel(1);
}
try this, copy/paste all
Does the player gameobject have an actual 2D collider?
not sure about this, but I believe it should be Colider2D.gameObject.tag
Answer by yuzriekhalid · Apr 07, 2016 at 10:26 AM
If I'm not late to answer this, void OnTriggerEnter2D (Collider2D Colider)
is the part where you need to fix. If you want a collision then do void OnCollisionEnter2D (Collision2d collision)