TO SQUASH: Added multiplier spawner

This commit is contained in:
2026-08-06 09:00:43 -04:00
parent 1dd8b8b786
commit f314b74e6c
19 changed files with 1257 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
using UnityEngine;
using System.Collections;
public class Multiplier : MonoBehaviour
{
public AudioClip multiplierSound;
public AudioClip missedSound;
public AudioClip gotItSound;
public AudioClip gotHalfSound;
private int multiplierValue = 0;
private float multiplierTimer = 0f;
private float stateTimer = 0f;
private bool isActive = true;
private AudioSource audioSource;
private Animator multiplierAnimator;
private SpriteRenderer multiplierSpriteRenderer;
private static float stateDuration = 0.5f;
private static float multiplierDuration = 30f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
audioSource = GetComponent<AudioSource>();
multiplierAnimator = GetComponent<Animator>();
multiplierSpriteRenderer = GetComponent<SpriteRenderer>();
audioSource.PlayOneShot(multiplierSound);
}
// Update is called once per frame
void FixedUpdate()
{
stateTimer += Time.fixedDeltaTime;
multiplierTimer += Time.fixedDeltaTime;
if (stateTimer >= stateDuration)
{
stateTimer = 0f;
multiplierValue = ((multiplierValue + 1) % 4);
multiplierAnimator.SetInteger("bonus", multiplierValue + 1);
}
if (multiplierTimer >= multiplierDuration && isActive)
{
isActive = false;
audioSource.PlayOneShot(missedSound);
multiplierSpriteRenderer.enabled = false;
StartCoroutine(DestroyAfterDelay());
}
}
private IEnumerator DestroyAfterDelay()
{
yield return new WaitForSeconds(1.5f);
Destroy(gameObject);
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9c5f36d6d3cd0528480676885849702e
+60
View File
@@ -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
)
);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2e3452dfae854c9ec802a4e8fce2813c