I am adding a button (or a text box with an added button component) to a canvas (which has an Event System). I then add an empty game object and add script to it…
using UnityEngine;
using System.Collections;
public class Doo : MonoBehaviour {
public void NextLevel()
{
Debug.Log("hghgh");
}
}
I add this to the button by adding an OnClick() event and dragging the game object to it and finally selecting the function from the drop down.
I had the same issue and for me to fix it all I had to do was leave unity and relaunch the project and it worked. I would give it a try then message me back and let me know if it worked.
Your setup should work, I tried it and the debug run. Do you see the button highlighting? (you probably do since it’s red and hard to miss) Can you connect the button to some other simple function and test?
Make sure that in your Touch Input Module, “Force Module Active” is unchecked. It seems like it might be an issue with raycast processing order. Also, try re-ordering child GameObjects if you have trouble with any UI elements. We had most our UI up and running, but a few elements were still broken. Once we moved those child elements lower in our list, they seemed to fire back up and work.
FWIW - it looks like a bug that should be corrected in newer releases.
i was facing the same issue, the issue was due to event system. in my project event system was merged with canvas object, i solved it by removing Event System script and Standalone Input module from my canvas and created new Event System after that it is working fine for me.
I had the same issue and move my button to the bottom of the components in the Canvas hierarchy solved the issue, but still sometimes need to Play it a few times until the button works properly.
I should have said that the button highlights when you move over it, but does not change colour when I press it (even when the ‘Pressed Colour’ is changed). I have tried it with other functions and I get nothing. I also get nothing when I add a breakpoint.
I have also rebuilt the whole thing varying everything I can think of. Still nothing!!!