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 /
avatar image
0
Question by Achala · May 09, 2016 at 09:54 AM · dropdown

Unity DropDown.OnValuechanged not working

I am trying to add a dropdown to a scene where the user selects an option and it updates the playerprefs and when app restarts, the selected option on the dropdown should be the one previously selected by the user.

The code I have come up with so far is as follows.

 public Dropdown mViewerTypeDropDown;
     void Start () {
         mDebug = (LRDebug)mScriptHolder.GetComponent<LRDebug> ();
         mScriptHolder=GameObject.Find ("ScriptHolder");
         mViewerTypeDropDown.captionText.text = PlayerPrefs.GetString ("Viewer Type","Generic Cardboard (Default)");
 
     }
 //The Function attached to onvaluechanged listner
 public void ViewerTypeChanged(int value)
     {
 
         mViwerTypeChange = value;
 
         switch (mViwerTypeChange) {
         case 0:
             mViewerType = "Generic Cardboard (Default)";
             break;
         case 1:
             mViewerType="VR ONE (Zeiss)";
             break;
         case 2:
             mViewerType="VR Goggles (Merge)";
             break;
         case 3:
             mViewerType="C1-Glass (Go4D)";
             break;
         case 4:
             mViewerType="Cardboard v1 (Google)";
             break;
         }
 
         PlayerPrefs.SetString("Viewer Type",mViewerType);
         PlayerPrefs.Save ();
     }

This seems logically right to me but I am not sure of what I am missing here. And to be further clear I have made the attached method a dynamic one in the editor as follows alt text

I have searched a lot but as this dropdown option is a new one There are not many examples out yet. So as a unity newbie I cannot seem to work this one out. If anyone could help me with this it will be a great help. thank you

screen-shot-2016-05-09-at-95155-am.png (35.7 kB)
Comment
Add comment · Show 1
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 athrael · Apr 26, 2017 at 08:53 AM 0
Share

Hi Achala,

I wonder if you have found a solution for this problem because I'm having the same issue and could not get it working even after thorough research on the internet. The problem is, no matter what option I select, the value won't change from 0. That is not how it's supposed to be working I guess?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by athrael · Apr 26, 2017 at 10:58 AM

Hi Achala,

I wonder if you have found a solution for this problem because I'm having the same issue and could not get it working even after thorough research on the internet. The problem is, no matter what option I select, the value won't change from 0. That is not how it's supposed to be working I guess?

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 PuzzleBuilder · Jun 28, 2018 at 08:24 PM

Instead of passing an integer value to the listener, try passing a Dropdown object, and in the editor choose the Dropdown to be passed to the listener. Then you can get the value of that Dropdown in your code. For example:

public void dropdownListener(Dropdown dd) { mViwerTypeChange = dd.value; }

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

6 People are following this question.

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

Related Questions

drop down list c# 1 Answer

Check marks in my dropdowns and disappearing UI elements... 1 Answer

Extending Unity's UI components 1 Answer

Make Dropdown option non-interactable 2 Answers

Dropdown with list of buttons instead of toggles 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