Created
December 2, 2017 21:50
-
-
Save MichaelPolla/b847162b015f3ff70097be5a36eaea23 to your computer and use it in GitHub Desktop.
[Unity3D] Execute code in Update() only at certain intervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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