balls respawn

main
Benjamin Kraft 1 year ago
parent 51a6d1fcea
commit f1fea51cd6
  1. 5
      Assets/Scripts/Game/Ball.cs
  2. 11
      Assets/Scripts/Game/GameManager.cs

@ -28,6 +28,11 @@ namespace Game {
private void Start() {
Rb.velocity = new Vector2(0, 25);
Rb.position = new Vector2(1, 0);
}
private void FixedUpdate() {
}
}
}

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.Netcode;
using Unity.VisualScripting;
using UnityEngine;
@ -90,5 +91,15 @@ namespace Game {
Tests();
}
private void FixedUpdate() {
foreach (var ball in Balls.Where(b => !b.IsAlive))
Destroy(ball.gameObject);
int count = Balls.RemoveAll(b => !b.IsAlive);
for (int _ = 0; _ < count; _++) {
Balls.Add(Instantiate(ballPrefab).GetComponent<Ball>());
}
}
}
}

Loading…
Cancel
Save