Resource system
ResourceObject.cs is an abstract class that represents a game resource. It includes properties and methods for managing the resource's value and for notifying other parts of the game when the resource's value changes. The resource data stores in player prefs.
LoadPrefs(): A method that loads the resource's value from PlayerPrefs.
Add(int amount): A method that increases the resource's value by a specified amount and saves the new value to PlayerPrefs. It also triggers the OnResourceUpdate event.
Set(int amount): A method that sets the resource's value to a specified amount and saves the new value to PlayerPrefs. It also triggers the OnResourceUpdate event.
Consume(int amount): A method that decreases the resource's value by a specified amount, if there is enough of the resource. It saves the new value to PlayerPrefs and triggers the OnResourceUpdate event.
OnResourceChanged(): A private method that triggers the OnResourceUpdate event.
GetResource(): A method that returns the current value of the resource.
IsEnough(int targetAmount): A method that checks if the resource's value is greater than or equal to a specified amount.
In example you could get coins value like this
Last updated