Collectables for the Player

How to create a Collectable System in Unity

Setup Steps

Pseudocode — Collectable System Scripts

Collectable Script

private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
other.GetComponent<Player>().Collectable();
Destroy(this.gameObject);
}
}

Player Script

[SerializeField] private UIManager _uIManager;
private int _collectables;
public void Collectable()
{
_collectables++;
_uIManager.UpdateCollectableText(_collectables);
}

UI Manager Script

using UnityEngine.UI;[SerializeField] private Text _collectableText;

public void UpdateCollectableText(int collectableCount)
{
_collectableText.text = "Balls: " + collectableCount;
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tristan Engel

Aspiring developer that’s self-learning Unity & C# to transition to a career with Unity. I got a passion for creating interactive experiences.