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
3
Question by anis1987 · Oct 02, 2015 at 11:27 PM · unity 5unity5dropdownaddoptions

How can i add a new item in dropdown options ?

Hi

I use Unity 5.2 version and i want to add a new item in dropdown options when i click into dropdown button using c#

i can clear option when i select an item from dropdownlist (see script bellow )but i want clear when i clicked into dropdown buton(onclick() don't exsit in dropdown script)

public Dropdown dd; dd.GetComponent().options.Clear() ;// clear option when i select an item from dropdownlist

thank you in advance

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 v3n0mou5 · Nov 02, 2015 at 03:38 PM 0
Share
 options.add();

you can use to add a new item in dropdown options

i dont know how to use that, looking for it my self but thats the function

1 Reply

· Add your reply
  • Sort: 
avatar image
9

Answer by Trigun666tn · Nov 22, 2015 at 02:28 AM

using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; using System.IO.Ports;

public class dd_Menu : MonoBehaviour {

 public Dropdown     Maindropdown;
 public Text         text;
 public string[]     ports;
 public static SerialPort sp = new SerialPort ("COM1",9600);// Refrence to serialPort 

 void Start () {

     // Fill ports array with COM's Name available
     ports = SerialPort.GetPortNames ();

     //clear/remove all option item
     Maindropdown.options.Clear ();

     //fill the dropdown menu OptionData with all COM's Name in ports[]
     foreach (string c in ports) 
     {
         Maindropdown.options.Add (new Dropdown.OptionData() {text=c});
     }

     //this swith from 1 to 0 is only to refresh the visual DdMenu
     Maindropdown.value = 1;
     Maindropdown.value = 0;
 }
 
 void Update () {
 
     //COM port Name that is currently selected on the dropDown Menu
     text.text = ports [Maindropdown.value];
 }

} Hey anis i use this script for my ports i think you will find every think you need in it . if you want to make the .clear() work with OnClick event you have to create another button/toggle and affect this function to it .

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 SpartanChief1170 · Jan 11, 2017 at 05:54 AM 1
Share

This was helpful as a dropdown example, but for future reference ins$$anonymous$$d of setting value twice you can do

 $$anonymous$$aindropdown.RefreshShownValue();

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

40 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Accessing my 'Options' panel from another script. 1 Answer

How to Setactive(true) the other class ? 0 Answers

OSX: The application is missing required entitlement com.apple.developer.icloud-services 1 Answer

Unity Ads not showing in editor (dummy ad placement is not showing too) as well as in the build. 2 Answers

Collision problems 0 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