Created
January 2, 2022 19:15
-
-
Save modyari/1adb6f97b147495e0f0d41d121650169 to your computer and use it in GitHub Desktop.
An example of using events to implement an achievment system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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