Need Help with Android Game Level Selection

Hello!
I am making a game that (when starts up) it goes to a menu-type screen with boxes for different levels. I am working on Android M using the latest public Unity, and could someone provide me with C# code for when someone taps the level box, it goes to the next scene. Thanks

I have code below, will it work?

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

public static void TouchInput () {
string = “Play”
if Input.GetTouch = //add the pixels here(??)
Application.LoadLevel string

}

Here’s the C# code you need:

        SceneManager.LoadScene (sceneName);

That’s all. But just in case you need all the stuff around that line that makes it usable, keep reading.

Create a C# script called GoToSceneButton and then paste this code into it:

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class GoToSceneButton : MonoBehaviour {
   
    public void GoToScene(string sceneName)
    {
        SceneManager.LoadScene (sceneName);
    }
}

Create an empty game object in your menu scene and name it SceneCode (that’s not technically required, but that’s the name I’m using in the following picture example). Now create a button and in the button’s On Click area make it look like this:

You’ll drag the SceneCode object into the lower-left location (where it shows SceneCode in the pic), and then in the upper-right drop down you’ll choose GoToSceneButton and then inside that you’ll choose GoToScene. Finally, you’ll type in the name of the scene you want to go to when the player clicks the button (in the example pic they’ll go to the scene named play).

I hope that helps.

Jay

Thanks for the code! But when I run it on my android device, it registers the tap, but it doesnt load the scene.

Code:

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class GoToSceneButton : MonoBehaviour {

    public void GoToScene(string accte)
    {
        SceneManager.LoadScene (accte);

    }

}

Double check that what you’re telling the code is the actual name of the scene. I’m not sure if upper/lowercase matters, but in case it does, make sure you’re not using “play” if the scene name is actually “Play.”

If you have a way to see console output from your Android device, put a Debug.Log line in above the LoadScene line, something like:

Debug.Log("accte: " + accte);

That way you can make sure that code is being executed and you have the name of the scene correct.

Jay

Oops Sorry! It works now =)