- Home /
input.getkey and loadlevel won't run
i have 3 scene 1.main menu 2.about (with button to camera) 3.some scene use camera device named (CameraPart) all of 3 scene have this script
using UnityEngine;
using System.Collections;
public class ScriptName : MonoBehaviour {
public void Update ()
{
if (Input.GetKey (KeyCode.Escape)) {
Application.LoadLevel("previous scene");
}
}
}
exept the main menu scene, main menu scene use this script
using UnityEngine;
using System.Collections;
public class ScriptName : MonoBehaviour {
public void Update () {
if (Input.GetKey (KeyCode.Escape))
{
Application.Quit ();
}
}
}
when I was in the "about" scene I can get back on the main scene menu properly, but when I've arrived at the scene "camera", when I try to hit the back button. application is not returned to the scene about, and even exit the aplication any ideas?
i've done with that, scene 2 to scene 1 work correctly, but scene 3 to scene 2 wont run. do i have to add more than 1 scene for the same scene?, for exemple i have to add scene 2 twice?
Answer by directusgames · May 08, 2015 at 01:22 PM
I would first start off by adding each scene into the build settings for unity, if you haven't already:
Select scene
On the toolbar, click "File"
Click "Build Settings"
Click "Add Current" underneath the "Scenes In Build" space.
Repeat steps 1 - 4 for each scene.
Note: You are best off adding them in the order you want them to progress (add Scene 1 first, then Scene 2, then Scene 3.)
Now assuming that I understand your scene flow correctly:
Scene 1 -> Scene 2 -> Scene 3
Your code for Scene 1 is correct.
Then for Scene 2 change your LoadLevel statement to:
Application.LoadLevel(0); //Index 0 is Scene 1
or
Application.LoadLevel("Scene1Name");
And Scene 3 should be:
Application.LoadLevel(1); //Index 1 is Scene 2
or
Application.LoadLevel("Scene2Name");
I haven't tested this but that should work.
Can I see your code? Are you receiving an error at all?