using System.Collections; using System.Collections.Generic; using UnityEngine; public class BubbleCounter : MonoBehaviour { public float width = 100; public float height = 200; bool drawGizmos = true; public List bubbles; void Update() { Collider2D[] colliders = Physics2D.OverlapBoxAll(transform.position, new Vector2(width, height), 0); List newBubbles = new List(); foreach (Collider2D collider in colliders) { if (collider.GetComponent() != null) { newBubbles.Add(collider.GetComponent()); } } bubbles = newBubbles; } void OnDrawGizmos() { if (!drawGizmos) return; Gizmos.color = Color.red; Gizmos.DrawWireCube(transform.position, new Vector3(width, height, 0)); } }