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 Yanger_xy · Jul 11, 2011 at 03:57 AM · floattextfieldscrollbar

How to input float in textfiled and and let the scrollbar change its value at the same time

Hello, everyone.I wanna to draw a Scrollbar and a textfield at the same time.And when the Scrollbar scroll, the textfield's value change with it, also, when the textfield's text changed, the Scrollbar change its position too. I write the code like this:

             GUILayout.BeginVertical();
             GUILayout.Label("目间距");
             _interocularDis = GUILayout.HorizontalScrollbar(_interocularDis, 0.01f, 0, 1f);
             _interocularDis = (float)Math.Round(_interocularDis, digit1);

             string textInterocular = GUILayout.TextField(_interocularDis.ToString());
             try
             {
                 _interocularDis = (float)Math.Round(_interocularDis, digit1);    
                 
                 //float tmp = float.Parse(textInterocular, System.Globalization.NumberStyles.AllowDecimalPoint);
                 float tmp = 0.0f;
                 float.TryParse(textInterocular, out tmp);
                 _interocularDis = tmp;

                // _interocularDis = (float)Convert.ToDouble(textInterocular);
                 
             }
             catch (Exception e)
             {
             }
         }
         GUILayout.EndVertical();


However, i can not input a float number in the textfield, how can i input a float number in the textfield and let the scrollbar change its value at the same time? Any answer will be appreciate!

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 GuyTidhar · Jul 11, 2011 at 05:55 AM

You are redefining "textInterocular" instead of just fetching the data.

Define the variable before calling the TextField() function or do that outside of the scope if you need to know of it outside of this scope:

 // Defined
 string textInterocular
 
 GUILayout.BeginVertical();
    GUILayout.Label("目间距");
      _interocularDis = GUILayout.HorizontalScrollbar(_interocularDis, 0.01f, 0, 1f);
      _interocularDis = (float)Math.Round(_interocularDis, digit1);

       // now you can change the value
       textInterocular = GUILayout.TextField(_interocularDis.ToString());
             try
             {
                 _interocularDis = (float)Math.Round(_interocularDis, digit1);    
 
                 //float tmp = float.Parse(textInterocular, System.Globalization.NumberStyles.AllowDecimalPoint);
                 float tmp = 0.0f;
                 float.TryParse(textInterocular, out tmp);
                 _interocularDis = tmp;
 
                // _interocularDis = (float)Convert.ToDouble(textInterocular);
 
             }
             catch (Exception e)
             {
             }
         }
         GUILayout.EndVertical();
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 Yanger_xy · Jul 11, 2011 at 09:18 AM 0
Share

it is not the variable "textInterocular"'s problem. I can not input float number either although defined it as a member variable.

avatar image GuyTidhar · Jul 11, 2011 at 09:42 AM 0
Share

it works fine for me..

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Textfield number only 1 Answer

How to make floats in the textfield? 1 Answer

[SOLVED] Huge terrains: how about player's coordinates precision? 1 Answer

if statement with floats in C# . what did i do wrong ? 0 Answers

Unexpected token if 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