Last active
March 22, 2021 15:42
-
-
Save paulmasri/412e5ed2aacfe616908433ea31874534 to your computer and use it in GitHub Desktop.
Equivalent of LateUpdate() but for FixedUpdate() in Unity
This file contains hidden or 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
| // Based on code by James Frowen https://james-frowen.github.io/unity_tips/latefixedupdate/ | |
| // but with order of execution switched so that LateFixedUpdate() is not called during OnEnable() | |
| public void OnEnable() | |
| { | |
| StartCoroutine(RunLateFixedUpdate()); | |
| } | |
| public void OnDisable() | |
| { | |
| StopCoroutine(RunLateFixedUpdate()); | |
| } | |
| private IEnumerator RunLateFixedUpdate() | |
| { | |
| while (true) | |
| { | |
| yield return new WaitForFixedUpdate(); | |
| LateFixedUpdate(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment