TO SQUASH: Added yummy cake.

This commit is contained in:
2026-08-06 20:00:41 -04:00
parent 49ea95bfe5
commit 456b5d998e
9 changed files with 230 additions and 92 deletions
+62 -3
View File
@@ -2,15 +2,74 @@ using UnityEngine;
public class CakeSpawner : MonoBehaviour
{
public GameObject cakePrefab;
public SpriteRenderer gameBoardSpriteRenderer;
private Bounds cakeBounds;
private Bounds gameBoardBounds;
private float spawnTimer = 0f;
private float spawnInterval = 10f;
private Vector2 spawnPosition;
private bool spawned = false;
private static float spawnProbability = 0.9f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
gameBoardBounds = gameBoardSpriteRenderer.bounds;
cakeBounds = cakePrefab.GetComponent<SpriteRenderer>().bounds;
Reset();
}
// Update is called once per frame
void Update()
void FixedUpdate()
{
if (!spawned)
{
spawnTimer += Time.fixedDeltaTime;
if (spawnTimer >= 1f)
{
spawnTimer = 0f;
if (Random.value < spawnProbability)
{
GameObject cake = Instantiate(cakePrefab, spawnPosition, Quaternion.identity);
}
spawned = true;
}
}
else
{
spawnTimer += Time.fixedDeltaTime;
if (spawnTimer >= spawnInterval)
{
Reset();
}
}
}
public void Reset()
{
spawned = false;
spawnTimer = 0f;
spawnPosition = new Vector2(
Random.Range(
gameBoardBounds.min.x + cakeBounds.extents.x,
gameBoardBounds.max.x - cakeBounds.extents.x
),
Random.Range(
gameBoardBounds.min.y + cakeBounds.extents.y,
gameBoardBounds.max.y - cakeBounds.extents.y
)
);
}
}