- Home /
Changing scenes by pressing a key press while being in a trigger
Here's my script:
if (Input.GetButton ("Jump") && other.gameObject.CompareTag("Exit_Scene"))
{
SceneManager.LoadScene (1, LoadSceneMode.Additive);
}
It looks like everything is fine, but when I enter the zone triggered "Exit_Scene" and push space button... Nothing happens! I've already put the scene I need in a "Build Settings" menu. Could anyone tell what have I done wrong?
Answer by tormentoarmagedoom · Mar 12, 2018 at 05:20 PM
Good day. I undertsnd this is inside a OnTriggerStay. If isnot, there is the problem...
If it's inside it, then check if is detecting the collision just before executring the "if" , check the 2 parts of the if using DEbug.Log, and checking the console.
Debug.Log (other.gameObject.tag;);
if (Input.GetButton ("Jump"))
{
Debug.Log("Button Clicked");
}
If they are executing, then check the inside of you if sentence. Replace the
SceneManager.LoadScene (1, LoadSceneMode.Additive);
with another
Debug.Log ("If Executed");
If this helped, please accept the answer :D
If this is executing too, your problem is in the parameters of LoadScence.
If you just want to load the next scene, use just
SceneManager.LoadScene (1);
And be sure you had added the scene "1" at your UnityBuild Panel
Enjoy! If helped, please accept the answer! :D
Thank you very much for your answer! I had some problems with tags) Now everything is solved.
Your answer