3D Minigame: SCORE! – 15/12/20

In todays session, for the 3D minigame I modified the FPSController script from the standard assets pack and made it so that we could pick up coins in the 3D minigame. To do this I made a int titled ‘Score’ and a Text game object titled scoreText. To add the Text game object, I had too add ‘using UnityEngine.UI’ to the collections.

After that, the next step is fairly simple, In the update function, I wrote ‘scoreText.text = “Score: ” + score;’ This will take our game object of scoreText and convert it into what we have wrote after the assignment operator. Then I made a new function which is called void OnTriggerEnter(Collider other). This is a built in function of unity that detects when one object passes through another. This uses a conditional statement.

So what this does, it checks to see if the player is passing through an object with the tag ‘Coin’. If this happens, it adds 1 to our score integer and then destroys the coin. Here it is in action.

Leave a comment