# Ball spawner

This method would be called when there's a need to spawn a new `Ball` in the game, such as at the start of a level or when a player makes a move that generates a new `Ball`. Use name of the prefab in parameter. Use SetPosition to put ball to the static position on the field.

Here's an example of how to use the `BallPool` to create a ball with a random color:

{% code overflow="wrap" fullWidth="false" %}

```csharp
var ball = PoolObject.GetObject("Ball 0").GetComponent<Ball>();
ColorManager.instance.GenerateColorInGame());

// set position on the field
ball.SetPosition((col,row));
```

{% endcode %}

In this case, we're creating a new ball at position (0,0) with a random color. The color is determined by passing the integer equivalent of `EBallColor.RandomColor` to the `SpawnBall` method. This enum value tells the method to assign a random color to the ball.


---

# 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/ball-spawner.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.
