After adding the code segments from the previous section, the fish should always be directly in the middle of the player’s view.
This newly implemented gesture steering/control provides the player a means to move about the virtual space, but there is currently no incentive to do anything in particular while present in the experience. Simple terms: it’s really boring.
To make this project a bit more engaging for the end user, we’re going to create a system of coins that will spawn throughout the game and need to be collected. Eventually, we’ll add in another script that will control when a coin is set active or inactive and provides arrows as a visual indicator to where the next coin is located.
Before getting to the more complex parts, we’ll start out by just working with the coin prefab itself.
In the “Models” folder in the “Swim Sim” project, you’ll find a “Coin” prefab.
Assets > Swim Sim > Models > Coin
The prefab’s tag should be “Coin” as well. If it is not, fix this now.
We’re going to process the fish colliding with the coin inside the “MainFish” script attached to the “Fish” object.
Add an “OnCollisionEnter()” function that will check if the colliding object is a coin by looking at it’s tag. If the other object is a coin, set it to inactive within the game’s hierarchy.