Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
1
Question by yDranzeer · Mar 19, 2015 at 10:10 AM · c#errorfunctiononclickmethod

My function doesn't appears in the OnClick button script

using UnityEngine; using System.Collections;

public class Database : MonoBehaviour {

 public int numSaves;
 public int[] save = new int[4];
 public string[] nome = new string[4];
 public bool[] pinOn = new bool[4];
 public int[] pin = new int[4];

 public void Salvar (string nome_, bool pinOn_, int pin_) {
     if (numSaves < 5)
     {
         save[numSaves + 1] = save[numSaves + 1];
         nome[numSaves + 1] = nome_;
         pinOn[numSaves + 1] = pinOn_;
         if(pinOn[numSaves + 1] != false)
         {
             pin[numSaves + 1] = pin_;
         }
     }
 }

}

2.png (382.0 kB)
Comment
Add comment · Show 4
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 Okido · Mar 19, 2015 at 10:26 AM 0
Share

Ah, didn't see that image link right away, I see what you mean now. Do you get any compiler errors on your Database Script?

avatar image Nerevar · Apr 24, 2015 at 12:27 PM 0
Share

Is this script on a gameObject in you scene?

avatar image pface444 · Apr 24, 2015 at 12:33 PM 0
Share

I have the same issue, did you find a solution for this? I am using UnityEngine.UI

avatar image pface444 · Apr 24, 2015 at 06:05 PM 0
Share
 ![using UnityEngine;
 using System.Collections;
 
 using UnityEngine.UI;
 public class UpdateValue : $$anonymous$$onoBehaviour {
     public Text text;
 //    public Slider slider;
     // Use this for initialization
 
 
     
     // Update is called once per frame
 
         public void UpdateText(float f) {
         Debug.Log ("f" + f);
         text.text = f.ToString(); 
     
     }
 }][1]
 

Hi Guys,

I have the same issue, however I am using UnityEngine.UI; And also only 1 float. I noticed others have issues as well...
I tried adding an empty object with script attached to it but onclick() doesn't take objects.

Any idea why I can only select $$anonymous$$onoScript and not actually the function, I am hoping I am doing something wrong! [1]: /storage/temp/45146-screenshot.jpg

screenshot.jpg (216.1 kB)

5 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Landern · Apr 24, 2015 at 12:36 PM

You have to many parameters. An OnClick event should be a public, void with one or no parameters/arugments. You have 3 parameters in your method, the single parameters should be either an int, string, bool, UnityEngine.Object or float by type.

http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-button

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
2

Answer by CorruptedTNC · Apr 24, 2015 at 12:37 PM

You can't call a function OnClick in the editor if it has more than 1 inbound parameter.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Test : MonoBehaviour 
 {
     public void FunctionWorks(string name)
     {
         Debug.Log(name);
     }
 
     public void FunctionDoesntWork(string first, string second)
     {
 
     }
 }

Example image

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 PvTGreg · Mar 19, 2015 at 10:27 AM

try including this

 using UnityEngine.UI;
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 eu1247 · Dec 26, 2016 at 07:05 PM 0
Share

Thanks a lot.

avatar image SquareMike · Sep 24, 2017 at 01:51 AM 0
Share

This worked, thanks!

avatar image
1

Answer by Teejs · Mar 12, 2017 at 07:31 PM

As Landern has pointed out, the OnClick event can only accept a single int, string, bool, UnityEngine.Object or float by type. But there is a workaround solution that can pass in multiple parameters. That is, create a utility class that contains the parameters you would like to pass in, and then pass in that class. For your case, what you can do is:

 //a separate utility class
 public class SalvarInfo : MonoBehaviour{
 public string nome_;
 public bool pinOn_;
 public int pin_;
 } 
 
 public int numSaves;
  public int[] save = new int[4];
  public string[] nome = new string[4];
  public bool[] pinOn = new bool[4];
  public int[] pin = new int[4];
  public void Salvar (SalvarInfo info) {
      if (numSaves < 5)
      {
          save[numSaves + 1] = save[numSaves + 1];
          nome[numSaves + 1] = info.nome_;
          pinOn[numSaves + 1] = info.pinOn_;
          if(pinOn[numSaves + 1] != false)
          {
              pin[numSaves + 1] = info.pin_;
          }
      }
  }

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
0

Answer by ForceVII · Feb 12, 2021 at 11:17 PM

If none of these work for you, probably you have parameter for you void but you arent using them. Use them or try removing parameter. example:

 public void Start(int sceneIndex)
 {
     SceneManager.Load(1);
 }

So remove "int sceneIndex" parameter from your void or use it in void.

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 ForceVII · Feb 12, 2021 at 11:18 PM 0
Share

I dont know why but it worked for me.

$$anonymous$$e:

It doesnt work. Why?

It works. Why?

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

10 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

Related Questions

My Function is not showing up in the OnClick Menu 2017.2.0f 0 Answers

what is wrong whis this? 1 Answer

Integer Getter Method always returns zero 3 Answers

Multiple Cars not working 1 Answer

How can I call a method from another script? 3 Answers


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