- Home /
How to delay Update() until Start() has finished?
public IEnumerator Start()
{
yield return StartCoroutine( imagine, say, an opening animation );
}
public void Update()
{
do not start moving, until that opening animation is done
ongoing movement etc.
}
I've always just done this with a simple flag:
public void Update()
{
if ( still doing that opening animation boolean ) return;
ongoing movement etc.
}
Is there perhaps some inherent way to know if Start() has not yet completed? Or another amazing solution? Cheers!
(Ed)Totally unrelated to the question, but of interest:(/Ed)
Checking for events happening is not something a programmer must do. The computer will do it for you. Have it fire the appropriate actions when you want; respond to that.
Action handleUpdate;
Action HandleUpdate
{
get { return handleUpdate; }
set
{
handleUpdate = value;
if (handleUpdate == null)
enabled = false;
else if (!enabled)
enabled = true;
}
}
event Action StartIsDone;
void Awake()
{
StartIsDone += () => HandleUpdate = UpdateAfterStart;
}
public IEnumerator Start()
{
HandleUpdate = null;
yield return StartCoroutine("whatever");
StartIsDone();
}
void Update()
{
HandleUpdate();
}
void UpdateAfterStart() {}
Answer by Jessy · Sep 22, 2013 at 11:44 PM
You can disable the script in Start().
Do this using enabled = false, same as anywhere else.
This is one of the greatest program$$anonymous$$g insights, ever seen.
This is one of the greatest program$$anonymous$$g insights, ever seen, since Alan Turing.
This is the greatest insight in to program$$anonymous$$g I have ever personally been witness to.
Your answer
Follow this Question
Related Questions
Initialising List array for use in a custom Editor 1 Answer
how to [Start a Timer] & Display as GUI 1 Answer
Does transform get copied before or after Start() called inside Instantiate() 1 Answer
A Script error With Void Start 2 Answers
Preventing my game object from multiplying due to DontDestroyOnLoad() 2 Answers