What your missing is an
Your button is passing an
OnClick event when you click on it; but without an
EventSystem to manage your events, this can have seemingly unpredictable results. The
EventSystem is its own component, and it does not appear to matter where you place it in your hierarchy, just as long as you only have one of them.
I personally had a very similar issue while testing an android prototype game I had made. It took me several months to figure it out, and even than, it wasn't me that figured it out - I also had to ask about it, here on GameDev. While someone was able to point out my initial issue through comments, I am still quite unclear on the overarching issue that had me confused; it appears (or at least, in my case) that input may work without an
EventSystem in an actual build. Assume it won't, and ensure you always include one. I keep one on my main camera, and have been able to successfully test your code with it.
If your using the
CrossPlatformInput package, you also need to ensure you have matching axis in your
Since you have not mentioned it, I assume you are not using the Unity package
CrossPlatformInput. Just in case you are, buttons still won't work if you do not have corresponding axis set in your
CrossPlatformInput to work, it needs to interact with four separate axis in your
InputManager: Vertical, Horizontal, Submit and Cancel. If you do not have these axis, fatal errors will block your
UI from handling input. Simply having these axis does not suitably set them up for
CrossPlatformInput, but having them there allows your other input to work as intended.