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?

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;
    }
}

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();
    }
}

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.

Have you tried this approach?

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