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
0
Question by lewispettinger · Feb 16, 2016 at 05:23 PM · c#menudropdown

Writing dropdown selections to file

Hi,

I'm fairly new to Unity and I have a dropdown menu on my UI menu and I'm attempting to write the currently selected option from the dropdown menu to a .txt file on pressing the return key but for some reason I keep getting the error:

Error CS1061: Type Dropdown' does not contain a definition for value' and no extension method value' of type Dropdown' could be found. Are you missing an assembly reference? (CS1061) (Assembly-CSharp)

Ive been experimenting with it first by simply trying to change some text to whatever option has been selected in the dropdown menu but I can't get past this error.

Heres the code:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections; 
 
 public class Dropdown : MonoBehaviour
 
 {
     public Dropdown menu;
     public Text text;
 
     void Start()
     {
     }
 
     public void ChangeOption()
     {
         switch (menu.value) 
         {
             case 0:
                 graph.text = "Deadlift";
                 break;
             case 1:
                 graph.text = "Bench Press";
                 break;
             case 2:
                 graph.text = "Overhead Press";
                 break;
             case 3:
                 graph.text = "Squat";
                 break;
         }
     }
 }


Any help would be greatly appreciated!

Thanks!

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 GoeTeeks · Feb 17, 2016 at 08:55 PM

Hi,

I'm trying to figure out how to print the text of the dropdown into a UI text. But let me point out a couple of things I noticed. You said you want to write to a text file? The syntax for that is quite a bit different than what you're using. The Text object you created is for Unity's UI Text. To write to a text file, you need to do a few things first. You might want to look up "how to write to a text file" before moving too far forward (I can't remember the exact syntax as it's been a while since I've used it. You need the right using, then you need to use something like System.IO.WriteToLine (/path/file.txt) or something like that). There's a few options.

If you're trying to write to the UI Text instead, just know that it's not considered a .txt file. I hope this helps a little bit.

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 GoeTeeks · Feb 17, 2016 at 09:02 PM 0
Share

Alright, as to how to print the string within a dropdown, use this:

menu.options[indexOfValue].text

where "indexOfValue" is the int value of the Dropdown (0 is the first option, 1 is the second, and so on).

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Cardboard SDK - Can't select options in drop down menu 1 Answer

Problem with enabling menu 0 Answers

Change scene by tapping a button in unity 5 UI System 1 Answer

Dropdown content out of bounds 1 Answer

Pause menu done exactly according to tutorial doesen't work 2 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