Skip to content

Instantly share code, notes, and snippets.

@MichaelPolla
Created December 2, 2017 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelPolla/b847162b015f3ff70097be5a36eaea23 to your computer and use it in GitHub Desktop.
Save MichaelPolla/b847162b015f3ff70097be5a36eaea23 to your computer and use it in GitHub Desktop.
[Unity3D] Execute code in Update() only at certain intervals
public class UpdateIntervals : MonoBehaviour {
private float updateStep = 0.1f; // in seconds
private float currentUpdateTime = 0f;
void Start() {}
void Update() {
currentUpdateTime += Time.deltaTime;
if(currentUpdateTime > updateStep) {
currentUpdateTime = 0f;
// Do something here
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment