Check if a value of a variable is changed

Hi,

I was wondering if there is a way to check that the value of a variable has changed.

Thanks!

Don’t think so. I think you’ll have to roll your own method of doing so.

Thanks!

I found a way to check if a value of a variable has changed. It maybe a little ‘messy’ but it works.

var a = 0;
var b = 0;

function Start(){
b = a;
}


function Update () {
	if (Input.GetKeyDown ("up")){
		a++;
	}
		
	if(a!=b){
		Debug.Log("value has changed");
		b=a;	
	}
}
4 Likes

please don’t reply to an ancient old thread. this thread is from 2011…
If you want to shout out your thanks just hit the like button instead

3 Likes