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 Bokaii · Jan 27, 2015 at 03:59 PM · c#uicanvasfunctionunity 4.6

Canvas Button OnClick() function arguments

When you make a ui button, and you want to add an event to it, you add a script to a gameobject, and you define the gameobject and use the script. But what if you need 2 function arguments? I need to define 2 things, in the same function, but when I try to find the function in the button event list, I doesn't show up, and I can't use it. Any idea how to have 2 function arguments?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Mmmpies · Jan 27, 2015 at 04:04 PM

Just do the two things in the one function in your script.

EDIT

Sorry that was a bit brief, the point is if you do an OnClick well it can only be clicked in one way so you have to put all your actions in the function that's called when OnClick happens.

If you want to something like have the button get switched on one one click and the switch off on the next one just make a bool called AmIOn and set it to be the opposite of itself every click.

 private bool AmIOn;
 
 public void BeenClicked()
 {
     AmIOn = !AmIOn;
 }

you can then check that bool in Update and do whatever actins you want if the buttom is on, e.g. rotate object.

Comment
Add comment · Show 5 · 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 Bokaii · Jan 27, 2015 at 04:28 PM 0
Share

Thank you for you're answer, but the problem is...

I want to have something like this:

 public Canvas canvas; //The main canvas, of which all the menus are gonna be stored in
 
 public void $$anonymous$$enuSwap(string name, string thisName){
     canvas.Find(name).GetComponent<Canvas>().enabled = false; //Find the main canvas, and then find a child-canvas with a name.
     canvas.Find(thisName).GetComponent<Canvas>().enabled = false; //Disable the menu which is currently enabled.
 }
avatar image Mmmpies · Jan 27, 2015 at 04:39 PM 0
Share

O$$anonymous$$ that makes more sense, pass it all as one string and use Split to separate the values out.

 public void BeenClicked(string $$anonymous$$yString)
 {
      string[] stringArray = $$anonymous$$yString.Split(':');
 

Where you pass it "FirstName:SecondName" as a single string.

Doouble check those commands though as I don't have access to Unity to test so just doing it from memory. Hopefully you should have enough to work out how to do it. I used a : but it could be anything like '\n' for a newline character.

avatar image Bokaii · Jan 27, 2015 at 05:08 PM 0
Share

How does it know where to split it? :) Would it be like, first capital after beginning? :?

EDIT

Never$$anonymous$$d, I facepalmed... ;) Split by type, Which is ":"

avatar image Mmmpies · Jan 27, 2015 at 05:29 PM 0
Share

:-) I think if you leave it empty it defaults to space if thats easier for you. I'll have access to unity soon so if you get stuck just let me know.

avatar image Bokaii · Jan 27, 2015 at 05:58 PM 0
Share

I will :D But it works! :D Thanks a lot! (Y)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Only Rotate UI HUD on orientation change. 0 Answers

How do I obtain children on UI canvas text 0 Answers

How to hide Canvas? 1 Answer

Trying to place an UI Canvas Image next to another UI Image 1 Answer

Multiple Cars not working 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