# 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.&#x20;

**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

```clike
ResourceObject coins;  // scriptable object which represents coins in this example

coins.LoadPrefs();  // init value from player prefs
int currentCoins = coins.GetResource();  // getting current coins amount
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.candy-smith.com/main/bubble-shooter-toolkit/scripts/scripts-overview/resource-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
