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 hollym16 · Aug 30, 2016 at 10:34 AM · uidropdownevent triggeringinteger

Drop down menu not working how I expected

I have a drop down menu that has a public void with an int variable. This allows you to select an option from the drop down menu during runtime and produce a function (in this case language selection). I assign the OnClick function as a Dynamic int in the Inspector.

However, I now want to add the same function to an Event Trigger (EndDrag) but when I try to assign the function, I only get Static Parameters, no dynamic ones.

Can anyone tell me how to access the Dynamic int?

My script:

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class DropDownMenu : MonoBehaviour {
     
 public Dropdown myDropdown;
 public static string key = null;
 public CanvasGroup ok;
 
 void Start() {
     myDropdown.onValueChanged.AddListener(delegate {});
         ok.alpha = 0f;
         ok.blocksRaycasts = false;
 }
 void Destroy() {
     myDropdown.onValueChanged.RemoveAllListeners();
 }
     public void SetDropdownIndex(int index) {
         myDropdown.value = index;
         if(index == 1){
             key = "English";
             Debug.Log ("English");
             TextLocalization.SelectLanguage("English");
             ok.alpha = 1f;
             ok.blocksRaycasts = true;
         }
         if(index == 2){
             key = "German";
             Debug.Log ("German");
             TextLocalization.SelectLanguage("German");
             ok.alpha = 1f;
             ok.blocksRaycasts = 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Aug 30, 2016 at 01:44 PM

You need to update your parameter to receive a MonoBehaviour type reference. I assume your dynamic value comes from a script then you pass that script as parameter to the listener. When the listener is called, it will go to the script and find the value at that moment:

 public class DataStorage:MonoBehaviour{
       private int index;
       public int Index{  get{ return this.index; } }
 }   
 
 public class DropDownMenu : MonoBehaviour 
 {
  
      public void SetDropdownIndex(DataStorage data) {
           myDropdown.value = data.Index;
           if(data.Index == 1){  
           }
           if(data.Index == 2){
           }
      }
  }

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 hollym16 · Aug 30, 2016 at 02:18 PM 0
Share

Thanks for the reply. I tried adding this scripting to the 'End Drag' Event Trigger but unfortunately it references the default index in the Inspector which is 0. I want it to work in the exact same way as the On Value Changed but just with End Drag ins$$anonymous$$d.

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

75 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 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

Use EventTriggers on GameObjects through the view of a RenderTexture.,Use Mouse EventTriggers on a scene rendered to a RenderTexture camera, 0 Answers

A problem with the dropdown items 0 Answers

Dropdown disable blocker 1 Answer

UI button kept being pressed 0 Answers

DropDown menu(add item from input field): Object reference not set to instance of an object C# 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