Adding spinning treat spawner

This commit is contained in:
hz
2026-01-31 21:57:16 -06:00
parent 86a860126e
commit 36422bbbc6
2 changed files with 71 additions and 0 deletions
+18
View File
@@ -11,6 +11,9 @@ public class Spawner : MonoBehaviour
[SerializeField] private int maxAlive = 0;
[SerializeField] private bool spawnOnStart = true;
[SerializeField] private bool repeatSpawns = true;
[SerializeField] private float launchForce = 0f;
[SerializeField] private float launchRandomAngle = 0f;
[SerializeField] private float spinSpeed = 0f;
private readonly List<GameObject> spawned = new List<GameObject>();
@@ -31,6 +34,14 @@ public class Spawner : MonoBehaviour
}
}
private void Update()
{
if (spinSpeed != 0f)
{
transform.Rotate(0f, 0f, spinSpeed * Time.deltaTime);
}
}
private IEnumerator SpawnRoutine()
{
// Infinite loop to keep spawning (can be modified)
@@ -66,6 +77,13 @@ public class Spawner : MonoBehaviour
var instance = Instantiate(objectToSpawn, transform.position, Quaternion.identity);
spawned.Add(instance);
if (launchForce > 0f && instance.TryGetComponent<Rigidbody2D>(out var body))
{
var angleOffset = launchRandomAngle > 0f ? Random.Range(-launchRandomAngle, launchRandomAngle) : 0f;
var direction = Quaternion.Euler(0f, 0f, angleOffset) * transform.right;
body.AddForce(direction.normalized * launchForce, ForceMode2D.Impulse);
}
}
private int CountAlive()