Update() method

##Unity 2D : Text101 : Manage Next States

If the Update() method in AdventureGame.cs is executed every frame…
and the ManageStates() method has
textComponent.text = state.GetStateStory();
outside the if / else if statements as the last statement, wouldn’t this assignment statement be executed EVERY frame?

Would it be better to have that assignment statement immediately after the state assignment inside the if / else if blocks. (granted there would be 3 text assignment statements instead of 1, but they would only be called when necessary) ?

Hi,

Welcome to our community! :slight_smile:

You are right. textComponent.text = state.GetStateStory(); gets executed each frame. Rick didn’t focus on performance optimisation because this is the first “complex” project in this course and the difference would not be noticeable in a little game like this.

I don’t know what exactly you mean because descriptions of code are always harder to interpret than the actual code but “inside the if / else blocks” sounds good. You definitely need some kind of a restriction to not have textComponent.text = state.GetStateStory(); executed each frame.


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms