Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Managing the PickUp Logic
Let's now add some logic that will let our character pick up the coin. We are going to use a Fungus Flowchart, that will be placed inside the PickUpCoin element.
Adding a Flowchart
Select PickUpCoin, click on Add Component and select Scripts > Fungus > Flowchart: click Open Flowchart Window to show the Flowchart.
Adding a 'Trigger Enter' Block
Create a command block, by using the + button in the Flowchart window and rename it TriggerEnter.
We need the block to become active on the MonoBehaviour > Trigger (FireOn > Enter) event, when an element enters in the GameObject Trigger.
Set the TagFilter field to 1 and, inside Element 0 insert "Player" (mind the uppercase!), so that only the Controller (which we tagged as "Player" in the previous lesson) will activate it.
We are now going to add some commands to the block.
Add an Usfxr Audio
First of all, let's add an Audio > Play Usfxr Sound command. In the Settings String field, add:
You can create your audio effects using the Fungus integrated editor selecting, selezionando Fungus > Utilities > Generate usfxr Sound Effects (for more info, please check the project page on GitHub).
Destroying the PickUp
Just after the audio effect, add a Scripting > Destroy command and drag the PickUpCoin gameobject from the Hierarchy panel into the Target Game Object field.
Playing the scene and moving the character on the coin, will result in the object being removed from game, just after the audio effect.
You are now ready to create a prefab out of the coin object.