Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by QuestionBro 5 · Mar 10, 2011 at 04:03 AM · guitextfieldchange variable

Way to tell if an int has been changed

is there a way to tell if an int has changed? or a string for that matter?

basically I am using textfields to change variables but when those variables get changed I need to know so that I can change another variable to a different number

how do I tell if a variable has changed or if a textfield has been edited?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by DaveA · Mar 10, 2011 at 04:19 AM

The GUI text fields should be updating as they are changed, that should be automatic, but in general, something like this:

var myInt : int = 0; private var last_myInt : int = 0;

function Update() { if (last_myInt != myInt) { DoSomething(); last_myInt = myInt; } }

Comment
Add comment · Show 4 · 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 QuestionBro 5 · Mar 10, 2011 at 04:22 AM 0
Share

The Textfields are updating fine, I am just looking to change a different variable when the user decides to change the variable in the Textfield (I have allot of Textfields and using a different variable solely for each one will get ridiculously large quickly) any simple function like textfield.haschanged? or way of doing something like that?

avatar image DaveA · Mar 10, 2011 at 05:40 AM 0
Share

If you check the code on this page: http://unity3d.com/support/documentation/ScriptReference/GUI.TextField.html The example shows exactly this. The assignment occurs when the user changes the text. Otherwise, use something like what I have (above) but using a string ins$$anonymous$$d of an int.

avatar image QuestionBro 5 · Mar 10, 2011 at 06:37 AM 0
Share

var stringToEdit : String = "Hello World";

function OnGUI () { // $$anonymous$$ake a text field that modifies stringToEdit. stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 25); }

that part is working completely fine, what I want to happen is when the user enters a variable into the text I want a CO$$anonymous$$PLETELY different variable to be changed to something CO$$anonymous$$PLETELY DIFFERENT that just changes a variable to what the user typed in

avatar image DaveA · Mar 10, 2011 at 07:46 AM 0
Share

Yeah same type of thing. See what yoyo has spelled out below

avatar image
0

Answer by yoyo · Mar 10, 2011 at 06:00 AM

I would do as DaveA suggests, though I would put the check into OnGUI where you edit the value, rather than in Update. Something like (C#, untested) ...

public string myString;

void OnGUI() { string newString = GUI.TextField(myString); if (myString != newString) { myString = newString; DoSomething(); } }

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 Gabriel 4 · Mar 24, 2011 at 02:15 PM

In C# you can use properties.

int myNumber = 5; // Your actual number

int MyNumber { get { return myNumber; } set { NumberChanged(myNumber, value); myNumber = value; } }

void NumberChanged(int oldValue, int newValue) { // Do stuff }

In your GUI code use MyNumber instead of myNumber. When the value is changed the NumberChanged function will be called.

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 BerggreenDK · Jul 29, 2011 at 07:13 PM

Have you tried this approach?

http://unity3d.com/support/documentation/ScriptReference/GUI-changed.html

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

1 Person is following this question.

avatar image

Related Questions

Set name for game 0 Answers

TextField, Event.current, Input.GetKey, and GUI.FocusControl locking 1 Answer

GUI.TextField 1 Answer

Convert.ToInt32 error 1 Answer

Can you have a scrollview inside a textfield? 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