Big script cleanup. Remove the examples from Ropes' external package
This commit is contained in:
74
Assets/Scripts/BubbleS/BubbleSpawner.cs
Normal file
74
Assets/Scripts/BubbleS/BubbleSpawner.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Spawns bubbles at intervals, randomizing their properties and assigning a random sprite to each.
|
||||
/// </summary>
|
||||
public class BubbleSpawner : MonoBehaviour
|
||||
{
|
||||
public Bubble bubblePrefab;
|
||||
public Sprite[] bubbleSprites; // Assign in inspector
|
||||
public float spawnInterval = 0.3f;
|
||||
public Vector2 speedRange = new Vector2(0.5f, 2f);
|
||||
public Vector2 scaleRange = new Vector2(0.3f, 0.7f);
|
||||
public Vector2 wobbleSpeedRange = new Vector2(1f, 3f);
|
||||
public Vector2 wobbleAmountRange = new Vector2(0.05f, 0.15f);
|
||||
public float spawnXMin = -3.5f;
|
||||
public float spawnXMax = 3.5f;
|
||||
public float spawnY = -5f;
|
||||
public float wobbleMinScale = 0.2f;
|
||||
public float wobbleMaxScale = 1.2f;
|
||||
|
||||
private float timer;
|
||||
private float nextSpawnInterval;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Initialize the next spawn interval
|
||||
nextSpawnInterval = GetRandomizedInterval();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
if (timer >= nextSpawnInterval)
|
||||
{
|
||||
SpawnBubble();
|
||||
timer = 0f;
|
||||
nextSpawnInterval = GetRandomizedInterval();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a randomized interval for bubble spawning.
|
||||
/// </summary>
|
||||
/// <returns>Randomized interval in seconds.</returns>
|
||||
float GetRandomizedInterval()
|
||||
{
|
||||
return spawnInterval * Random.Range(0.8f, 1.2f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawns a bubble with randomized properties and assigns a random sprite.
|
||||
/// </summary>
|
||||
void SpawnBubble()
|
||||
{
|
||||
float x = Random.Range(spawnXMin, spawnXMax);
|
||||
Vector3 spawnPos = new Vector3(x, spawnY, 0f);
|
||||
Bubble bubble = Instantiate(bubblePrefab, spawnPos, Quaternion.identity, transform);
|
||||
// Randomize bubble properties
|
||||
bubble.speed = Random.Range(speedRange.x, speedRange.y);
|
||||
bubble.wobbleSpeed = Random.Range(wobbleSpeedRange.x, wobbleSpeedRange.y);
|
||||
float scale = Random.Range(scaleRange.x, scaleRange.y);
|
||||
bubble.transform.localScale = Vector3.one * scale;
|
||||
// Assign random sprite to BottleSprite
|
||||
if (bubbleSprites != null && bubbleSprites.Length > 0)
|
||||
{
|
||||
Sprite randomSprite = bubbleSprites[Random.Range(0, bubbleSprites.Length)];
|
||||
bubble.SetBottleSprite(randomSprite);
|
||||
}
|
||||
// Random rotation
|
||||
bubble.transform.rotation = Quaternion.Euler(0f, 0f, Random.Range(0f, 360f));
|
||||
// Pass min/max scale for wobble clamping
|
||||
bubble.SetWobbleScaleLimits(wobbleMinScale, wobbleMaxScale);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user