TO SQUASH: Added multiplier spawner
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MultiplierSpawner : MonoBehaviour
|
||||
{
|
||||
public GameObject multiplierPrefab;
|
||||
|
||||
public SpriteRenderer gameBoardSpriteRenderer;
|
||||
|
||||
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;
|
||||
|
||||
if (spawnTimer >= 1f && isActive)
|
||||
{
|
||||
spawnTimer = 0f;
|
||||
if (Random.value < spawnProbability)
|
||||
{
|
||||
GameObject multiplier = Instantiate(multiplierPrefab, spawnPosition, Quaternion.identity);
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
isActive = true;
|
||||
spawnTimer = 0f;
|
||||
spawnPosition = new Vector2(
|
||||
Random.Range(
|
||||
gameBoardBounds.min.x + multiplierBounds.extents.x,
|
||||
gameBoardBounds.max.x - multiplierBounds.extents.x
|
||||
),
|
||||
Random.Range(
|
||||
gameBoardBounds.min.y + multiplierBounds.extents.y,
|
||||
gameBoardBounds.max.y - multiplierBounds.extents.y
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user