Unity 4.6 Button OnClick's Functions not showing.
I've made public functions in my scripts and attached the objects to the OnClick but I can't select or see any functions from the script.
I'm having the same issue. If it helps, here's more information: I'm using Unity 4.6.0b17. I've tried adding a few imports (using UnityEngine.UI and using UnityEngine.Events), I've tried using all of the different function signatures mentioned in the tutorial (making sure they're all public void). I've also tried inheriting from only $$anonymous$$onoBehavior and also inheriting from nothing. All I get are two options: No function and $$anonymous$$onoscript -> string name. None of the functions I'm putting in show up at all. I have even tried creating a brand new project, creating one button, creating one script with a function named public void foo(){} and still nothing shows up.
Any suggestions or other help would be appreciated. BTW, I am aware of adding it manually to the script to subscribe to the button handler. This is specifically looking at a possible issue in Unity.
The script with the class declaration and method would help.
Also a screen shot of the inspector with the button selected.
hi there, I've got the same problem and I've tried all your solutions and it still don't work, I've checked that my methods use int or nothing, that the return type is void, that they're all public methods, but nothing show up whn I want to assign a method to the button T.T
( does it matter if I've deleted start and update? 'cause I don't use them)
Answer by VincentZgueb · Oct 02, 2014 at 03:52 PM
Try this:
create an empty object in your scene
Attach your script to it (Drag and drop your script into that object inspector to create a scrip component)
in button
Drag and drop the object created above in the Object field on the OnClick event (and not the script itself from your Project tree)
That should work.
Thanks VincentZgueb! It seems like there's still a bug here, but your suggestion did work for me. I'd +1 but it says I don't have enough reputation :(
This didn't work for me. In fact, that's exactly what I had done, but my public methods for the script don't show on the drop-down. It seems it only shows the native GameObject methods. Has anyone had the same problem?
Ok, I figured it out. I hadn't noticed that the methods for On Click have to return void, and only accept int, float, bool, string, and Object parameters. $$anonymous$$y method received an enum, so I had to change it.
quick side note, if your function still doesn't appear, maybe it is because it has 2 or more Parameters in it, it seems unity only support 1 parameter at a time for function in button interface.
Thanks! It works if I drag the canvas in the button.The canvas need to have the script attached!
Answer by jsawicki · Jun 08, 2015 at 07:23 AM
I had the same issue - here is what worked for me.
I was dragging the script directly to the button, which doesn't work. I needed to drag the object which contains the script onto the button!
After i did that, the functions showed up!
Answer by JackTenSeven · Jun 03, 2016 at 06:05 PM
I have your answer! You need to make sure that the function that your trying to put on the button is a public function. If that doesnt work right away just re reference you object containing the script :)
Answer by zedzag · Jul 15, 2015 at 10:53 AM
see Diego's response: http://answers.unity3d.com/questions/972191/why-wont-my-function-show-up-in-the-onclick-area-o.html
Answer by StormMuller · Aug 07, 2016 at 01:43 AM
Make sure your method is void, public and has no more then 1 parameter.
examples:
public void Methodname()
{
}
public void Methodname(string param)
{
}
public void Methodname(bool param)
{
}
Also make sure your class and/or method is not static. Attach the script to a GameObject and drag the gameobject onto the onClick event in the inspector. Select the method you wish to execute on the click.