As a result of the coronavirus (COVID-19) outbreak, we have a reduced capacity to review effects and delays in publishing are expected. Learn more.
You can use the Patch Editor to add logic and interactivity to your effects. In this guide, you'll make a color in your effect change in response to different interactions using the If Then Else and Counter patches:
For these examples we're going to use a Screen Tap patch, which detects a tap of someone's finger on the device's screen and outputs a boolean signal. You could use any other patch that outputs a boolean signal. To see what kind of signal a patch outputs, check the menu in the Patch Editor.
This guide uses Counter and If Then Else to show different colors. They can be used for other types of effect, for example to play different animations or make objects become visible in the scene.
You can use the If Then Else and Switch patches to switch between 2 options in response to an interaction from the user. In this example, we'll use these patches to change the color of a material each time a tap is detected.
Start by opening the Patch Editor. Then, right-click in the Patch Editor and select:
You'll also need a to create a patch representing the property you want these patches to change. For this example:
If you select the If Then Else patch and expand the blue box at the bottom of the patch, you'll see it can output different types of data. Select Color.
The option you'll select here depends on the type of effect you're creating. If you were using these patches to switch between two animations, you'd select Animation Data instead.
Next to Then and Else, click the color symbols on the patch to choose new colors for the material:
Your graph should look like this.
As a result of connecting these patches, each time the screen is tapped, a switch is turned on or off. When it's on, the material will take the color added next to Then in the If Then Else patch. When it's off, it'll change to the other color.
You can test this in the Simulator, by selecting Simulate Touch from the menu and clicking anywhere in the Simulator:
To count between more than 2 options in response to an interaction, you can use the Counter and Option Picker patches.
Right-click in the Patch Editor and select:
You'll also need a patch representing the property in the scene object that you want to change. Like before, for this example we'll use the Diffuse Texture property in a material, to change the color.
The Counter patch can be use to count through different options, which we'll set in the Option Picker patch.
You can use the ports and adjust the values in the Counter patch to count through options in different orders, or jump to a specific option.
The Option Picker can accept and output different data types - like animation, boolean signals and color. For this example, select Color. To set color options in the Option Picker, click the value next to each port. For this example, set a different color in each one.
Connect the patches, so your graph looks like this:
Make sure the Maximum Count is set to match the number of options you've set in the Option Picker. We've set the Maximum Count to 4, to show 4 colors.
To show a random option in your effect, all you need to do is replace the Counter patch with a Random patch. Make sure the End Value in the Random patch matches the number of options you've set in the Option Picker patch.