Wonder what the best practice would be for this situation

hey everyone,

What I am wondering is what the best programming/scripting practices would be when coding in something that you only want to be called the first time a situation is met, then not again.

for example. I want a tutorial window to show up the first time someone find 1 apple, but in the future after that event happens the first time i do not want the window to continue to keep popping up interrupting the game.

i know that i could all ways do a simple if statement to call the window when the apple is >= 1, but what would i do to ensure this doesn’t happen if the player eats the first apple, then goes and finds another?

Thanks for any information!

Static variables are your friend! They are global, not specific to an instance of your script. So if you have this in Apple.cs:

 public static hasSeenAppleTutorial = false;

(You may want to set it to false in some script’s Awake function or in your main menu or something; static variables can persist outside of play mode sometimes)
…then you can check against Apple.hasSeenAppleTutorial, and set it to true when you display the tutorial.

1 Like

Store the value in PlayerPrefs. So when they open the game the next time, check the value in PlayerPrefs, and show the tutorial if they haven’t seen it yet.

Usually you can have a global object manager or singleton, which you can use to get and set various game values from your data store. Some people like to refactor these into several object managers, such as TutorialManager, GameManager, SoundManager etc.

1 Like

awesome, thank you! for some reason i did not even consider the player prefs as an option for this… I should have.

thank you for that idea as well. Helps me to see a couple different ways you can accomplish the same goal :slight_smile:

Coroutines can also be used.

1 Like