Execute Code Once per Play Session


I have a game with diferent levels that can be accessed either through a level selection menu, or by beating the previous level.

I want to have a flyby play only ONCE per play session… so the first time they see the level in that play session the flyby plays, if they access the same level again during that play session there’s no flyby.

If the player shuts the app and relaunches a few minutes later it should reset and play all flybys.

Any ideas how to make this happen?


Create an object in the first scene in your game that is loaded.

Attach a script to it that invokes the following in either Awake/Start:


This will make the object (and any child objects) persist between levels.

This way, you could put some values into this script that your Flyby code checks before its run, to see if you’ve already played the flyby for a specific level.

You could probably accomplish the same with a Singleton object that doesn’t inherit from MonoBehaviour, but the above method would prove easier to debug.

Create an empty parent game object (i.e. it is not a child of any game other game object). Then in a script attached to that game object do:

function Awake(){
    // Insert one-time code here