public void Update() { foreach (var lhs in particles) { foreach (var rhs in particles) { if (lhs != rhs && (lhs != null && rhs != null)) { if (CollisionDetector2D.DetectCollision(lhs, rhs)) { if (!toBeDeleted.Contains(lhs)) { toBeDeleted.Add(lhs); } if (!toBeDeleted.Contains(rhs)) { toBeDeleted.Add(rhs); } } } } } foreach (var particle in toBeDeleted) { particles.Remove(particle); Destroy(particle.gameObject); } toBeDeleted.Clear(); }
private void Awake() { if (instance == null) { instance = this; DontDestroyOnLoad(this.gameObject); } else { Destroy(gameObject); } }