Everytime my character destroys an enemy, I have a variable that increases by 1.
If two successive enemy destructions (and variable increases) happen too fast (eg in less than a second), I want something to happen (eg activate a sound, or change a boolean var). I think that I should somehow use deltaTime.
How do I check how much time passed between 2 successive value changes of a variable (in this case chainHits var)?
Thanks for reading :-)
If you are using C# and are using properties, you can just capture a DateTime inside the property setter, or as part of the property changed event. Then every time it's set just see if the last set was before a certain time. If it is, do something.
If you are not using C#, this (data encapsulation) is just one of the great reasons you should consider the switch ;-). Seriously, if you are not and are using UnityScript you will need to encapsulate the access of that data inside of a method (like a setter) and do what I described above. Just exposing a public variable will not do this.
The last and really nasty, not elegant solution would be to note the value in a second variable, then periodically, perhaps in Update or LateUpdate see if the original is different note the time.
That's psuedocode of course, but hopefully you get the idea.