- Home /
 
Changing scene with button android
Hi everyone. I thought that changing my scenes was an easy part of my project but it doesn't work.I'm creating an android project. I have a menù and some buttons in it. I made the script with the function for changing scene. The button is interactable. I put this function in the OnClick () of the button. But either with the mouse and with the unity remote the button doesn't work at all. What am I missing? Thanks
using UnityEngine; using System.Collections;
public class MenùSelector : MonoBehaviour {
public void SceneSelector (int ScenesIndex) { Application.LoadLevel (ScenesIndex); }
}
It could be a problem with the UI ? All of my buttons don't change color when highlighted or pressed...
I don't know if it has anything to do with your question but there is a grave accent in $$anonymous$$en*ù*Selector.
Answer by KdRWaylander · Jul 20, 2015 at 08:20 AM
Hi, i don't think you can have a parameter in the function you call: int ScenesIndex is never set.
 public void SceneSelector () {
    int ScenesIndex;
 
    //You need to find a condition like with checkboxes
    //or based on the name of the button that calls this function
 
    /*
    if () {
       ScenesIndex = 1;
    } else if () {
       ScenesIndex = 2;
    }
    */
 
    Application.LoadLevel(ScenesIndex);
 }
 
              I thought that this parameter would be passed from the inspector in the OnClick () function. Example: When I press the button It changes Scenes from Scene 0 to scene 1 . The index 1 or 0 can be choosen in the build settings.
If you just wanna switch to next scene with one button you can use that:
 public void LoadNextScene()
     {
         var nextLevel = (Application.loadedLevel + 1) % Application.levelCount;
         Application.LoadLevel(nextLevel);
     }
 
                 Your answer
 
             Follow this Question
Related Questions
Android: Scene change (Application.LoadLevel) has no effect 3 Answers
How to make a No Ads Button 0 Answers
Android Button With Raycast 3 Answers
Onscreen fire button for FPS games. 1 Answer
Android Error 0 Answers