Adding spinning treat spawner
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user