TO SQUASH: Added FruitBall prefab, animation, and script. Updated BallSpawner to spawn FruitBalls.

This commit is contained in:
2026-08-03 00:02:04 -04:00
parent b073fc0785
commit f3627df2e9
18 changed files with 1258 additions and 4 deletions
+14 -1
View File
@@ -30,7 +30,8 @@ public class BallSpawner : MonoBehaviour
ballQueue.Enqueue(() => SpawnBasicBall());
ballQueue.Enqueue(() => SpawnBasicBall());
ballQueue.Enqueue(() => SpawnBasicBall());
ballQueue.Enqueue(() => SpawnBasicBall());
ballQueue.Enqueue(() => SpawnFruitBall());
ballQueue.Enqueue(() => SpawnFruitBall());
StartCoroutine(SpawnBalls());
}
@@ -47,6 +48,18 @@ public class BallSpawner : MonoBehaviour
Instantiate(basicBallPrefab, spawnPosition, Quaternion.identity);
}
private void SpawnFruitBall()
{
if (fruitBallPrefab == null || gameBoard == null)
{
Debug.LogWarning("BallSpawner: Missing fruitBallPrefab or gameBoard reference.");
return;
}
Vector3 spawnPosition = GetRandomPositionInsideGameBoard();
Instantiate(fruitBallPrefab, spawnPosition, Quaternion.identity);
}
private Vector3 GetRandomPositionInsideGameBoard()
{
Bounds bounds;
+65
View File
@@ -0,0 +1,65 @@
using UnityEngine;
public class FruitBall : MonoBehaviour
{
private Animator animator;
public AudioClip spawnSound;
public AudioClip bounceSound;
public AudioClip hitSound;
private AudioSource audioSource;
private Vector2 speed;
private float speedMultiplier = 1.0f;
private float speedIncreaseTimer = 0.0f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
audioSource = GetComponent<AudioSource>();
animator = GetComponent<Animator>();
speed = new Vector2(Mathf.Sign(Random.Range(-1f, 1f)) * 0.0001f,
Mathf.Sign(Random.Range(-1f, 1f)) * 0.0001f);
audioSource.PlayOneShot(spawnSound);
}
// Update is called once per frame
void Update()
{
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
if (stateInfo.IsName("FruitBallMove")) {
transform.Translate(speed * speedMultiplier);
}
if (speedIncreaseTimer > 0.0f)
{
speedIncreaseTimer -= Time.deltaTime;
if (speedIncreaseTimer <= 0.0f)
{
speedMultiplier = 1.0f; // Reset the speed multiplier to 1x
}
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Wall") || collision.gameObject.CompareTag("Ball"))
{
ContactPoint2D contact = collision.GetContact(0);
speed = Vector2.Reflect(speed, contact.normal);
if (collision.gameObject.CompareTag("Ball"))
{
speedIncreaseTimer = 2.0f; // Reset the timer to 2 seconds
speedMultiplier = 50.0f; // Set the speed multiplier to 7x
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fc75c31387827597c81cd1228c0e31ac