Photo by Denny Müller on Unsplash
Introducing Parcel Counters And Money Systems
Creating a player inventory system...
The Parcel Counter
When creating the parcel counter I decided that I want this to work in the same way as coin collection systems often seen in games. In order to do this I placed a box collider on the parcel and enabled the trigger option so that it could be destroyed once the player collides with the object. I also added in some UI elements and connected this to a player inventory I created so that the number of parcels could be seen.
This worked well in single player however I quickly found this caused issues when multiple players were in the match. The parcel counter UI of each player was overlapping with one another creating a jumble of numbers. Therefore to overcome this issue, instead of parenting the UI to a shared canvas within the level, I parented the UI to each individual player. Additionally I applied the ‘DeactiveIfNotMine’ script I had created last week to the player UI which also helped resolved remaining conflicts. Whilst this is not a perfect fix it was a good way for me to test the parcel counter for the time being.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class DeactiveIfNotMine : MonoBehaviourPunCallbacks
{
// Start is called before the first frame update
void Start()
{
if(!photonView.IsMine)
{
gameObject.SetActive(false);
}
}
}
A short but very useful piece of code!
The Money Counter
Initially I had assumed that since I had already created the UI and player inventory system for the parcel counter, the money counter would be simple. However, in order for players to make money they had to drop off their parcels to delivery points. This meant that I had to implement a parcel checker within the delivery point script. In order to to this I had to get access to the player inventory with PlayerInventory playerInventory = other.GetComponent<PlayerInventory>(); whilst within the trigger box of the house. If parcels was greater than zero and the player was within the house trigger, a parcelDelivered() event within the player inventory script would be called. This would award them with money which would then be displayed on the players personal UI. I decided to design the way I would implement the code in a flow diagram for greater clarity when implementing this code.
I used this code flow diagram to help me plan out the sequence of events that needed to occur in order for a successful delivery to be made.
Conclusion
Currently there are no images for the number of parcels or for the money. This is something I plan to include in a future update. Additionally, as you can see from the short clip above, due to the way that I have parented the camera to the player, the top down camera is extremely restricting and not fun to drive around with. In future updates I am planning on improving the camera to look a bit more like this clip from overcooked. Thanks for reading!