Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Caruzo · Oct 24, 2015 at 07:42 PM · textmenudropdown

Showing what a user has chosen from a dropdown menu

First of all, thank you for your help:

I have two things: an InputField and a dropdown menu.

I have an empty text asset which shows the text written in the inputfield with the following code: alt text

The thing that I try to accomplish is to get the same result from a dropdown menu: the choice to be displayed in another empty text asset.

I simply tried to change the userName and "UserName" to userContinent and "UserContinent" due to the fact that my empty text asset is called UserContinent but unfortunately it did not work.

I personally think the issue comes from the string variable because it is not a string in the dropdown menu but something else that I cannot seem to find.

Any help will be appreciated

inputfield.png (12.8 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

1 Reply

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

Answer by Statement · Oct 24, 2015 at 09:10 PM

Example project (Unity 5.2.2f1)

  • UIYourNameInputField.cs

  • DropdownTrigger.cs

So, you can hook up to events from the Dropdown component like you did with InputField. However, the Dropdown event only gives you a single index. It's useless without a reference to the Dropdown. I solved this by adding a custom event trigger to the Dropdown that forwards both the Dropdown that sent the event and the selected index.

If you use that DropdownTrigger that I sent, you only need to add one more function to your existing code:

     public void userNameShow(Dropdown dropdown, int index)
     {
         userName.text = dropdown.options[index].text;
     }

And then you need to bind the event from DropdownTrigger to your userNameShow function. Look at this illustration.

Make sure that you add a On Value Changed handler on Dropdown Trigger. Set the receiver to your game object that has your script, and select the function from the Dynamic list (pink).

If you want to know how it gets to execute your code and set the text, read on. Otherwise you can ignore the rest.

EventSystem sends (red) input to Dropdown. Dropdown sends On Value Changed event to Dropdown Trigger. Dropdown Trigger sends (green) On Value Changed event to your userNameShow function. Your function sets the text of UserName.

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 Caruzo · Oct 24, 2015 at 11:36 PM 0
Share

Thank you a million times! I made it work! You are a genius (hehe, I am still at beginners level, know 80% of javascript though)!

avatar image z25assassins · May 10, 2017 at 08:01 PM 0
Share

Thank you!

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

32 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

Related Questions

Writing dropdown selections to file 1 Answer

Scrolling of drop down menu 1 Answer

How do you do a dropdown menu that changes resolution? 0 Answers

Dropdown.ClearOptions does not work 1 Answer

Trouble loading game save data with BlazeSave after uploading a new Steam build 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