I have just started working with Unity, so I’m experiencing all the thrills and joy of learning a new programming suite from the ground up. All I want to do is create at OnClick function and link it to my button. Here is the code I’ve got:
public class btnSceneSelect : MonoBehaviour
public void LoadSceneSelect ()
SceneManager.LoadScene( 1 );
Here is a screenshot of the LoadSceneSelect function NOT appearing for selection for use with the OnClick event. The only option that appears under Monoscript is “string name”:
When you clicked on On Click() little circle to add your Script, you need to be under the Scene tab, not the Assets tab. Hopefully this helps!
If this is the Happiecat vids, you may also need to change the coding in script.
public class SceneSelectButton : MonoBehaviour
public void LoadSceneSelect()
That should be all you need to change to get buttons to work!
Kinda late, but if anyone else is facing this issue, make sure that the function in your script is set to ‘public’ ( ie public void function() ) instead of just void funtion() which is sometimes set to private by default. Should work after that.
Hi guys, I know this is an old post, but for me what happened was that I was requesting a type Enum as the function’s first argument.
It only shows up if I change that to a more predictable type like string, int, etc. I’m guessing Unity doesn’t really know how to handle custom Enums in the UI.
Hope this helps other people with the same issue!
you need to drag and drop Game Object you attached the button to.
Button1 inside panel1
you have to drag and drop panel1 in OnClick inside button1 script.
because you attached the script to panel1
then you will find the Public functions only available in last one (which is the name of the script) of the listview
Certain functions won’t show up in the list. If your function has any non-primitive types in its parameter list, the button won’t be able to press it. It can take int, string, bool, float, and so on, including MonoBehaviour and its subtypes. But it doesnt work on any struct or enum type. It also accepts methods with no parameters.