Checking if an integer has changed

In one script, I have it so that when the player interacts with an object, one is added to an integer. I need to find a way to say basically;

if (1+ is added to this integer)
{
  do whatever
}

But no matter what I try, it never works.

Hello @amylclarkson,

I’m not completely sure what you want but I guess what you mean is when your variable changes you want to call a function, you can use Getter / Setter inside your variable:

private int _myCount; // Variable used for the getter / setter

public int myCount {

   get {
      return this._myCount;
   }

   set {
      int oldValue = this._myCount; // keep the old value for the test
      this._myCount = value; // attribute the new value

      if (this._myCount == oldValue + 1) { // compare the change
         // do what you want
      }
   }
}