Skip to content

Instantly share code, notes, and snippets.

@modyari
Created January 2, 2022 19:15
Show Gist options
  • Save modyari/1adb6f97b147495e0f0d41d121650169 to your computer and use it in GitHub Desktop.
Save modyari/1adb6f97b147495e0f0d41d121650169 to your computer and use it in GitHub Desktop.
An example of using events to implement an achievment system
public class Achievements : MonoBehaviour
{
//..More code here
private void Awake()
{
Item.OnCollectedItem += HandleItemCollected;
}
private void OnDestroy()
{
Item.OnCollectedItem -= HandleItemCollected;
}
private void HandleItemCollected(Item item)
{
if (item is SpecialItem)
{
UnlockSpecialItemsAchievement();
}
}
private void UnlockSpecialItemsAchievement()()
{
//..Unlock achievement
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment