Snapchat Lens created with Lens Studio. You will hunt birds by clicking them, and you have ten seconds to catch as many as you can.
Download and install Lens Studio
Once Lens Studio is installed, open it and create a new project from template Look Around
- Remove unnecessary birds
- Add timer resource
Resources -> Add New -> Texture -> Animated from files...
Then rename the imported resource as timer
or something else more descriptive.
-
Repeat the previous step, but import counter instead of timer
-
Resources -> Add New -> Import files... ->
result.png
- Objects -> Add New -> Billboard
-
Remove
2D Sprite 1
underEffects
-
Highlight
Effects
-
Object -> Add New -> Sprite
-
Rename the added Sprite to
timer
-
Highlight
timer
and from the bottom-right section under Sprite options click the BaseTex property (should sayDefault
) -
Choose
timer
-
On top of the bottom-right section change
Layers
fromDefault
toOrthographic
-
Under the transform section, adjust position and scale accordingly.
-
Repeat steps 4 - 9 with
counter
-
Again, add a new Sprite, rename it to
background
. Set Material -> Add New -> Unlit -
Highlight
Unlit
from Resources and change BaseColor to green or whatever you like. -
Select
background
again, resize and reposition. -
Repeat steps 4 - 9 with
result
-
Repeat steps 4 - 9, but rename the Sprite as
resultNumber
and addcounter
as BaseTex
Now, you're project should look something like this.
- Highlight
Chick_FBX
underLookAroundObjectController
, and then Objects -> Add New -> Mesh Visuals -> Box
-
Rename it to
TouchCollision
-
Resize and reposition it to cover just the whole bird
-
Highlight
TouchCollision
and select Material 1. Add New -> Unlit -
Highlight the newly added Unlit material from Resources
-
Uncheck
Depth Test, Depth Write and Color Write
to make the box invisible -
Highlight
TouchCollision
-
From the bottom-right section, choose Add Component -> Touch. Then choose
Mesh visual 1
and selectTouchCollision
-
Highlight
TouchCollision
-
Add Component -> Script -> Add New -> Script
-
From Resources, choose
Script
-
Paste the below code to the script text field
// -----JS CODE-----
// @input SceneObject item
// @input Component.SpriteVisual counter
// @input Component.SpriteVisual timer
// @input Component.SpriteVisual resultText
// @input Component.SpriteVisual result
// @input Component.SpriteVisual resultBg
var counterControl = script.counter.mainPass.baseTex.control;
var timerControl = script.timer.mainPass.baseTex.control;
var birdsTapped = 0;
// Hide results
script.resultText.enabled = false;
script.result.enabled = false;
script.resultBg.enabled = false;
// Set counter to zero
counterControl.pauseAtFrame(0);
timerControl.pauseAtFrame(0);
// Bind the function to the touch event.
var touchEvent = script.createEvent("TapEvent");
touchEvent.bind(moveItem);
// Bind the timeout function to delayed event.
var timeoutEvent = script.createEvent("DelayedCallbackEvent");
timeoutEvent.bind(function(eventData) {
timerControl.pause();
// Show results
script.resultText.enabled = true;
script.result.enabled = true;
script.resultBg.enabled = true;
// Hide timer, counter and item
script.timer.enabled = false;
script.counter.enabled = false;
script.item.enabled = false;
});
// Move bird, increase counter and show the amount of tapped birds
function moveItem () {
if (birdsTapped === 0) {
timerControl.play(1, 0.0);
timeoutEvent.reset(10);
}
script.item.getTransform().setWorldPosition(randomPosition());
birdsTapped++;
counterControl.pauseAtFrame(birdsTapped);
}
function randomPosition () {
var x = randomNumber(-25, 25);
var y = randomNumber(-25,25);
var z = randomNumber(-150, -50);
return new vec3(x, y, z);
}
function randomNumber (min, max) {
return Math.random()*(max - min) + min;
}
-
Apply Changes
-
Highlight
TouchCollision
-
From the bottom-right section under Script, match the following:
Item -> Chick_FBX Counter -> counter Timer -> timer Result Text -> result Result -> resultNumber Result Bg -> background
Choose timer
from Resources, and check Reverse
and set duration to 11,00