The Scavenger Hunt Example is an example of using Scan by Snapchat in real life environment.
To add the Scavenger Hunt Example to your project, go to the Asset Library tap on top right corner of your Lens Studio, and search for 'Scavenger Hunt'. Then click on the Import button to import this to your project.
Drag and drop the prefab asset into the Objects panel under an Orthographic Camera.
You can create an Orthographic Camera by adding a Screen Image or Screen Text.
Now you should be able to see the Scavenger Hunt game popping up in the Preview channel!
Using a Custom Preview or Export to Mobile
In order to conveniently test out this example, please download this preview and add it to Lens Studio with the + From Files option on top of the Preview panel.
The Scavenger Hunt Example is created with a simple state machine logic.
The State Manager script is the central script that controls the flow of the state machine. It'll call the initial state to be started, and check to enable the next state if previous state is finished. All states that are put here will be called in a sequential order.
On each state object there's a StateScript attached, and on each StateScript there are input fields for 'hint' objects StartStateObjects that are enabled when this state is active, then 'response' objects PassStateObjects that are enabled when the state has 'passed'. It'll also have a StatePassTime which determines length of displaying the response object.
In the example of State1 where the Hint is asking players to find a 'cup'. The 'hint' object contains all the texts appeared in the scene.
*All 'hint' and 'response' objects are disabled by default but will be disabled by scripts and only enabled when the game is in the appropriate state.
Then once the lens recognize a cup, it'll enable the response object and related graphics will show up in scene.
Using Behavior Triggers
Besides toggling objects in scene, the scavenger hunt is also set up with Behavior triggers. You can observe triggers being called in the logger when states are entered and passed.
Here's a standard sequence of each state:
STARTSTATE + Number of this state (state entered)
Waiting for PassState trigger
PASSSTATE + Number of this state
Playing pass state animation (length of this is defined by the StatePassTime variable on each State script.
STARTSTATE + Number of the next state
We can observe them in logger when we have printMessage turned on on the StateManager script.
Each STARTSTATE trigger is called from the previous state when the next state is triggered. We can see that is called in the State script graph under the comment area 'Trigger Next State'.
Each PASSSTATE trigger is done differently in each state. It can be called from a Behavior script or a custom script. For the states that request user to scan to find objects, it is usually being triggered from the TargetScan script, which can be found attached to objects titled 'Trigger X'.
We can take a look at the Trigger 3 object under State3_Puppy. The TriggerScan script will scan under the category from Scan Type and look for matching result from the value of Target Objects input field.
In this case TriggerScan will start scanning the scene once STARTSTATE3 trigger is called, and will trigger PASSSTATE3 once the label 'Dog' is found in the scene.
We can add custom Tween animations or any responses (such as playing sounds, enable object tracking, calling script API, etc) with Behavior scripts when PASSSTATE happens to make rewarding visuals and sounds when player has identified objects successfully!
We can find related examples under each State object with objects labeled 'Behavior'.
Feel free to go through the objects in scene to explore different setups with Behavior and Tween!
Feel free to toggle the Persistent Storage option on the Scavenger Hunt object in the StatesManager script! The usePersistentStorage variable allows the lens to remember the progress of your scavenger hunt. It comes quite in handy if the Scavenger Hunt list become long so that user can have their progress saved even when they refresh the lens!
Since Scan understands what’s in the scene by sending it to a server, the Snapchat user must accept permission to enter the Scan experience. We can program custom response in the lens that let users know whether they're using the full functionality of scan.
That's it for this guide on using the Scavenger Hunt Game! Feel free to replace the assets and create your own Scavenger Hunt Game!