> For the complete documentation index, see [llms.txt](https://docs.candy-smith.com/main/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.candy-smith.com/main/bubble-shooter-toolkit/scripts/scripts-overview/resource-system.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
