bubble_shooter_2d/Assets/Scripts/BubbleCounter.cs
2025-06-02 09:21:48 +05:30

37 lines
896 B
C#

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<Bubble> bubbles;
void Update()
{
Collider2D[] colliders = Physics2D.OverlapBoxAll(transform.position, new Vector2(width, height), 0);
List<Bubble> newBubbles = new List<Bubble>();
foreach (Collider2D collider in colliders)
{
if (collider.GetComponent<Bubble>() != null)
{
newBubbles.Add(collider.GetComponent<Bubble>());
}
}
bubbles = newBubbles;
}
void OnDrawGizmos()
{
if (!drawGizmos)
return;
Gizmos.color = Color.red;
Gizmos.DrawWireCube(transform.position, new Vector3(width, height, 0));
}
}