Last active
May 14, 2025 13:35
-
-
Save hariedo/e396ec4ca807bea97885079ac67227ca to your computer and use it in GitHub Desktop.
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
// The magical Start() method can also be treated as a coroutine if it returns | |
// IEnumerator. This lets a component class behave linearly, or at least start | |
// up with linear logic such as waiting for the right conditions to begin the | |
// Update() loop. | |
public class WaitToStartBehaviour: MonoBehaviour | |
{ | |
// all the usual Singleton stuff (optional) | |
public VitalThing vital = null; | |
public List<ImportantThing> importantThings = new(); | |
public bool IsEverythingReady() => | |
vital != null && importantThings.Count > 0; | |
IEnumerator Start() | |
{ | |
while (!IsEverythingReady()) | |
yield return null; | |
DoStartupStuffThatNeedsEverythingReady(); | |
} | |
DoStartupStuffThatNeedsEverythingReady() | |
{ | |
//... | |
} | |
// all the other things this class does | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment