- Home /
Not Working properly. Application.LoadLevel
My player has the tag of FPSController, but when I collide with the plane that has that script, the level does not change, in build settings, the next level is 2
void OnTriggerEnter(Collider other) {
if (other.gameObject.CompareTag("FPSController")) {
Application.LoadLevel (2);
}
}
Current Code:
public class ToLevelTwo : MonoBehaviour {
private string[] scenePaths;
void OnTriggerEnter(Collider other) {
if (other.gameObject.CompareTag("Finish")) {
SceneManager.LoadScene(2);
Current Code:
public class ToLevelTwo : $$anonymous$$onoBehaviour {
private string[] scenePaths;
void OnTriggerEnter(Collider other) {
if (other.gameObject.CompareTag("Finish")) {
Scene$$anonymous$$anager.LoadScene(2);
}
}
}
Try explicitly comparing tag. So..
If(other.gameObject.tag == "Finish")
Using CompareTag is the appropriate thing to do here, ins$$anonymous$$d of directly checking string equality.
Answer by Habitablaba · Jun 14, 2017 at 06:36 PM
Application.LoadLevel has been deprecated. You should be using SceneManager instead. Specifically, LoadScene
You can also use the override that takes a string to provide the name of a scene instead of the scene index, but that's really up to you.
So should i not use application? when i replace LoadLevel with LoadScene, it makes the error: 'UnityEngine.Application' does not contain a definition for 'LoadScene'
i added. using UnityEngine.Scene$$anonymous$$anagement; and it stopped the errors, but still it wont send me to scene 2
Try using the name of the scene ins$$anonymous$$d of the index. Does this solve the problem? Are you using 2 as the index because your scene is 2nd in the list? I think the scene index may be 0 based (I don't have Unity accessible right now so I can't test to be sure), which would mean you actually want scene index 1 ins$$anonymous$$d of scene index 2
Answer by Arcticstar · Jun 14, 2017 at 11:01 PM
Make sure to Add both scene to Build on the Build settings
Answer by Lupinus · Jun 14, 2017 at 11:12 PM
I had similar issues. Add a debug.log statement inside your OnTriggerEnter function and have it output a text message to the log. It doesn't matter what it says, just trying to determine if it's a loadscene issue, or if it's a triggering issue. Each would have different possible causes. Let us know whether or not the debug message shows up. :)
Answer by achristopher · Jun 15, 2017 at 08:54 PM
Stupid me, i forgot to make the plane's collider "Is trigger". My final script was:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ToLevelTwo : MonoBehaviour {
private string[] scenePaths;
// Use this for initialization
void OnTriggerEnter(Collider other) {
if (other.gameObject.CompareTag("Finish")) {
SceneManager.LoadScene("Term Game 1");
}
}
}
Glad to hear it's working for you. We've all been there... myself included. :) And thanks for posting your fix... this may be helpful to others.
Your answer
Follow this Question
Related Questions
Restarting a Scene 1 Answer
Don't destroy on load not working? 4 Answers
Why won't my terrain load. 0 Answers
How to create multiple ARworldmaps with ARKit using unity3d in a single app? 0 Answers
Loading bar with visual bar 1 Answer