I would like to work out the change in a variable from the last update.
so something like x(i+1) - x(i) but in a c# way. I am pretty new to c# so any help would be great! I can’t use the built in mouse position and getaxisraw etc because the x and y data is not coming from the mouse.
Hope this makes sense to someone!
Hello @KateHassan,
The thing you are looking for is properties and delegates.
public event Action<int> OnVariableChanged = delegate { };
public int X
{
get
{
return x;
}
set
{
int oldValue = x;
int newValue = value;
//Here you can find out difference
x = value;
OnVariableChanged.Invoke(value);
}
}
This way you can keep on track when a variable, for example, is changing in the set block and in the more elegant way using delegates like:
private void Awake()
{
OnVariableChanged += OnVariableChangeHandler;
}
private void OnVariableChangeHandler(int value)
{
//Do something when variable change
}
Please feel free to ask any questions you might have.
All the best,
The Knights of Unity