0

I make the game on android. There are two scenes: main and menu. Accordingly, the main one is for game play, and the menu one is for the game menu to launch the main one. The script is the same for both the Start button and the Restart one (after losing).

using UnityEngine.SceneManagement;

void OnMouseDown()
{
    SceneManager.LoadScene("menu");
}

This code is hung up on the picture.

On PC all works correctly, the transition is performed. But as soon as I try it on Android, the Start button simply doesn't work and the game won't start. But if I remove restart in the menu then it works. What's the problem? Forgot to add that the click occurs at the picture with a Box Collider. In Build Settings both scenes are added.

Tekerin
  • 1
  • 1
  • Are you sure the even it being raised? Could something be hiding (covering) the button and therefore preventing the event being raised? – pookie Jun 14 '17 at 21:20

1 Answers1

3

Forgot to add that the click occurs at the picture with a Box Collider.

You do not attach BoxCollider to a UI Button. Hopefully, that's not what you are doing. You have to subscribe to the onClick event if this is a UI Button. See this post for more information.

On PC all works correctly, the transition is performed, but as soon as I try on Android, the start button simply doesn't work and the game won't start

I assume you meant to say this works fine in the Editor but not on the Android. If this is true then add your scene to the "Build Settings" then rebuild your game. Any scene you need to load must be added to the "Build Settings".

Note that the default/first scene to load should the first scene in the "Build Settings". If they are already added make sure they are enabled by checking the checkbox to each scene before building the project again.

enter image description here

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • I wrote that in the Build Settings of both scenes added. And it not only works in the editor, but after compilation on the PC. But when adding the buttons I noticed that when it is clicked on Android if the program hangs, because the button stays in "pressed" position. – Tekerin Jun 15 '17 at 05:25
  • You need to update your question with the code you use to detect the click. The one line of code in your question is not enough to help you. – Programmer Jun 15 '17 at 05:28
  • My code clicking the picture with the Box collider and the loaded script. By the way I want to add that the restart button on the main scene with the same script reloads the scene successfully. And with menu On main and in turn does not want to go. `void OnMouseDown() { SceneManager.LoadScene("menu"); }` – Tekerin Jun 15 '17 at 05:34
  • You just want a button that you click and the scene reloads? – Programmer Jun 15 '17 at 05:38
  • On the stage main button restart, its task is to restart the level. On the stage of menu start button, its task is to run the main stage. If I restart the scene, then everything is fine. If you go to another scene, it hangs on andriod. – Tekerin Jun 15 '17 at 05:40
  • Do not use `void OnMouseDown() { SceneManager.LoadScene("menu"); }` for that. Read the first part of my answer. Create a UI Button then use the code I provided in the link. Read where it says [**2.Button Component:**](https://stackoverflow.com/a/41392130/3785314). – Programmer Jun 15 '17 at 05:48
  • This method is also not working. In the editor everything works, but after compiling on android button is pressed (even visually obvious), but the stage does not pass. – Tekerin Jun 15 '17 at 19:55
  • You have to edit your question and add the new code that's not working. Also add screenshot of the Object the script is attached to. – Programmer Jun 15 '17 at 20:01
  • And maybe the possibility that the problem is with the sdk? I re-installed sdk, but the result is not given. And actually, the original code written in the subject. On andriod not working absolutely no way. – Tekerin Jun 15 '17 at 20:09
  • I may not be able to continue helping because you're not helping yourself. What does SDK have to do with this? I have been talking about you using UI Button and even provided a link but you still ended up using `OnMouseDown` and even updating your question with `OnMouseDown`. It means all these comments I have made are taken into account at-all. – Programmer Jun 15 '17 at 20:14
  • I'm trying to convey that it is not in the code. ANY code does not work the same way. He will click through, let it be through a picture, Yes, even through text. The game is being compiled on a andriod hangs. 5 days I am suffering with this problem, no solution helps. – Tekerin Jun 15 '17 at 20:24