2026-08-06 09:00:43 -04:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
2026-08-25 22:24:07 -04:00
|
|
|
public class MultiplierSpawner : Spawner
|
2026-08-06 09:00:43 -04:00
|
|
|
{
|
|
|
|
|
public GameObject multiplierPrefab;
|
|
|
|
|
|
|
|
|
|
public SpriteRenderer gameBoardSpriteRenderer;
|
|
|
|
|
|
2026-08-27 17:14:18 -04:00
|
|
|
public WorldFiller worldFiller;
|
|
|
|
|
|
2026-08-06 09:00:43 -04:00
|
|
|
private Bounds multiplierBounds;
|
|
|
|
|
|
|
|
|
|
private Bounds gameBoardBounds;
|
|
|
|
|
|
|
|
|
|
private float spawnTimer = 0f;
|
|
|
|
|
|
|
|
|
|
private Vector2 spawnPosition;
|
|
|
|
|
|
|
|
|
|
private bool isActive = true;
|
|
|
|
|
|
|
|
|
|
private static float spawnProbability = 0.1f;
|
|
|
|
|
|
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
gameBoardBounds = gameBoardSpriteRenderer.bounds;
|
|
|
|
|
multiplierBounds = multiplierPrefab.GetComponent<SpriteRenderer>().bounds;
|
|
|
|
|
Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
spawnTimer += Time.fixedDeltaTime;
|
|
|
|
|
|
2026-08-25 22:24:07 -04:00
|
|
|
if (spawnTimer >= 1f && isActive && isSpawning)
|
2026-08-06 09:00:43 -04:00
|
|
|
{
|
|
|
|
|
spawnTimer = 0f;
|
|
|
|
|
if (Random.value < spawnProbability)
|
|
|
|
|
{
|
2026-08-27 17:14:18 -04:00
|
|
|
spawnPosition = worldFiller.GetRandomPositionInFreeAreas(multiplierBounds);
|
2026-08-06 09:00:43 -04:00
|
|
|
GameObject multiplier = Instantiate(multiplierPrefab, spawnPosition, Quaternion.identity);
|
|
|
|
|
isActive = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
|
|
|
|
isActive = true;
|
|
|
|
|
spawnTimer = 0f;
|
|
|
|
|
}
|
|
|
|
|
}
|