Unity3D and Fungus Tutorial: PickUps

Anonymous
92.1K views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Tracking Points

Let's show how many points the player is getting for collecting coins.

Creating Variables

First of all, we need two variables for tracking:

  • how many points a coin is worth
  • how many points the player has collected

Open MainFlowchart and, from the Variables section, click the + button twice, creating two integer variables called PointsPerCoin and TotalPoints. Assign a value of 10 to PointsPerCoin.

Creating Variables

Update Points

We already know when a coin has been collected... so we are now ready to assign points. Select the On Coin Collect block and add a Variable > Set Variable command, that let us assign a value to a variable. Set the variable to TotalPoints, select += as the operator (adds a value to the variable) and PointsPerCoin as the value.

Setting a Variable

Save the scene and play it: each time a coin is collected, TotalPoints will be updated.

Testing the Scene

Show Points in the UI

The last thing to do is to show in the UI the updated points the player has gained (we'll use the same text element as the one used for the welcome message).

With the On Coin Collect block selected, add a UI > SetText command, drag the Text element in the Hierarchy panel into the Target Text Object field, and add the following text:

```{$TotalPoints} Punti````

The syntax {$variable-name} interpolates, during play, the variable value in the text.

Updating the UI

Open Source Your Knowledge: become a Contributor and help others learn. Create New Content