Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
25
Question by D_Ventin · Aug 07, 2016 at 06:25 PM · scripting problembeginnereventsonclick

Function Not Appearing In OnClick Editor

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:

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 using System.Collections;
 
 
 public class btnSceneSelect : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     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":

alt text

I think we can all agree that LoadSceneSelect is a public void function with no parameters.

I would appreciate any insight that could be offered. Thank you!

onclick.png (72.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

11 Replies

· Add your reply
  • Sort: 
avatar image
74
Best Answer

Answer by TBruce · Aug 07, 2016 at 06:52 PM

Instead of selecting the C# class, select the GameObject that btnSceneSelect is attached to.

If btnSceneSelect is not attached to a GameObject, attach it to one (other than the button).

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image D_Ventin · Aug 07, 2016 at 07:03 PM 1
Share

I imagine it should also be recommended that this "attached GameObject" be an EventsSystem. I take it that's what it's there for?

Thanks!

avatar image nicmarxp · Jul 30, 2018 at 05:34 AM 3
Share

Also the method needs to have zero or one parameter, or it will not show up.

avatar image MerlinsMaster nicmarxp · Feb 14, 2019 at 06:12 AM 0
Share

So if it has two parameters, it will not work? Is there a workaround for that? I have a function that will set the screen resolution, so I need two parameters.

avatar image nicmarxp MerlinsMaster · Feb 14, 2019 at 12:11 PM 1
Share

Correct, you should be able to use an array or a custom object to do that. See more here: https://answers.unity.com/questions/785134/ui-button-multiple-parameters.html

Show more comments
avatar image SufianDira · Jun 19, 2020 at 08:55 PM 0
Share

You can indeed attach it to the button itself and it works fine.

avatar image
21

Answer by tyfoon3s · May 08, 2017 at 06:43 AM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NKBDL · Oct 23, 2020 at 09:45 AM 0
Share

O$$anonymous$$G that was a silly one but I guess pretty obvious once you know it... Thanks dude

avatar image Toasticuss · Dec 23, 2021 at 08:47 AM 1
Share

It also helps to ensure you have all required semi colons and no compile errors. I missed a compile error in the bottom left which is easy to miss since the error message is so small on a big monitor.

avatar image KyleRLamble Toasticuss · Jan 28 at 06:55 PM 0
Share

I had compile errors that I wasn't paying attention to yet. This was preventing unity from actually updating my list to contain my new functions.

avatar image
18

Answer by PutridCarcass · Mar 14, 2018 at 09:41 PM

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.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class SceneSelectButton : MonoBehaviour
 {
 
     // Use this for initialization
     void Start ()
     {
         
     }
     
     // Update is called once per frame
     void Update ()
     {
         
     }
 
     public void LoadSceneSelect()
     {
         SceneManager.LoadScene(1);
     }
 }

That should be all you need to change to get buttons to work!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image imrajatgupta · Mar 11, 2019 at 01:38 AM 0
Share

Your answer actually solved my problem. I was in Assets every time. Thanks a lot! :)

avatar image KuanHsin · Aug 13, 2020 at 04:20 PM 0
Share

This answer helps. alt text

註解-2020-08-14-003101.png (7.1 kB)
avatar image
3

Answer by sambid123sameer · Aug 07, 2016 at 07:20 PM

Select the button as a gameobject instead of the script

i mean you have attached the script containing the script to that button

Drag that button into the field instead of the script

Also you can do it via script too

http://answers.unity3d.com/questions/779226/unity-46-getcomponentonclick-how-do-you-add-an-eve.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by BradOZman · Oct 13, 2016 at 04:24 PM

I seen this so many times everywhere and doesnt help me.

I am using a game object with script attatched.

I can see the script name and a bunch of other functions but not the methods I put in the script.

They are public void and no parameters.

Im doing everything right cant get it to show up.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Danim3D · Nov 16, 2017 at 12:25 PM 0
Share

I solved my issue of the fonction not showing by adding a Static instance of my $$anonymous$$enu$$anonymous$$anager script which allows it to be accessed by any other script and the OnClick Editor. Just adding theses two lines:

 public static $$anonymous$$enu$$anonymous$$anager Instance;
 
 void Awake(){
     Instance = this;
 }
  • 1
  • 2
  • 3
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

108 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I can't figure out why this variable is not updating 0 Answers

OnClick() event script from a prefab 0 Answers

Certain scripts that are attached does not work after build, scene change and closing unity 0 Answers

"Win32Exception: The System cannot find the file specified" 0 Answers

How do I use a function’s return value as a parameter in another function? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges