Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Danor · Apr 21, 2015 at 06:16 PM · c#buttonunity 4.6

need my function to take 2 variables and show in OnClick list

I wrote a function for a set of buttons but after i wrote & built, it didn't show up in the OnClick function list on my buttons so i looked around on google and found out that you can't do this(no idea why though). I don't know how to work around this problem so i'm hoping one of you guys have a good idea.

In my game i have a lot of stuff that can be bought, each item has it's own panel and buy button which is supposed to open a different panel ment for all transactions("shop"), this panel includes 2 price texts, 1 for each currency. So a function that takes 2 variables so i can set it differently for each button in the editor seemed like an easy and effective way to do it.

here's the script:

 public void OpenShop(int creditcost, int crystalcost){
         CheckFunds();
         creditsCostText.text = creditcost.ToString();
         crystalsCostText.text = crystalcost.ToString();
         if (ShipMenu.activeInHierarchy == true) {
             panelOpened = false;
             ShipMenu.SetActive(false);
         } else {
             WeaponMenu.SetActive(false);
         }
         Shop.SetActive(true);
     }
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Chmava · Apr 27, 2016 at 12:29 PM

Try this:

 public void OpenShop (string item = "100,100")
 {
     string[] split = item.split (","[0]);
     int creditcost = int.Parse(split[0]);
     int crystalcost = int.Parse(split[1]);

and when you use it:

  OpenShop ( CreditCost.toString() + "," + CrystalCost.toString() )

This might not be the best way around it. Unity really need to support multiple variables for UI Button onClick event.

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 Thebotgame · Dec 12, 2019 at 09:44 AM 0
Share

Thanks it works

avatar image
0

Answer by TheSorm · Apr 27, 2016 at 10:26 AM

Just put the variables in an array of objects[] and give that array to the function

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 HarshadK · Apr 27, 2016 at 10:36 AM

There are a couple of options provided in this question: UI Button multiple parameters

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

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

23 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

Related Questions

Multiple Cars not working 1 Answer

HELP how to use buttons 1 Answer

Distribute terrain in zones 3 Answers

Trigger a Button Click 2 Answers

Rotating Tank Turret with correct angle 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