Framework 1: Collecting Points
Now that we have created the UI Manager and have linked both the player script and the UI manager script to communicate with each other, it is time to create the actual collectable.
Prepping the Collectables:
To begin, we first need to create an collectable object, for now we can use a regular sphere as a place holder, and we can refine the object later.
To finish preparing the sphere as a collectable object, we need to make sure that the Collider is set to “is Trigger” as true. Then we are going to create a new C# script which we will named “Collectable Behavior” and drag the script into the Sphere collectable.
Scripting the collectable:
Open the script and delete both the Update and Start Method. Instead we are going to use an On Trigger Enter event where it will be tracking the tag “Player”.
Once the collider has made contact with the player game object we are going to trigger an public method “Add points” from the player script. (this public method was created during the last article when we were prepping the UI manager)
Then we are going to add an “Destroy” function to create the illusion that the collectable has been picked up.
Back in Unity, we are going to create a prefab of the collectable object so we can reuse the prefab over and over again.
Now when we play the scene we will see that the collectable has been added to our player data and is shown wihtin the UI Manager.