using System; using UnityEngine; public class NoiseSystem : MonoBehaviour { public static NoiseSystem Instance { get; private set; } [SerializeField] private bool _debugMode = false; [SerializeField] private LayerMask _enemyLayer; public event EventHandler OnNoiseEmitted; private void Awake() { // Singleton pattern if (Instance != null && Instance != this) { Destroy(gameObject); return; } Instance = this; } public void Emit(Vector3 position, float radius) { if (_debugMode) Debug.Log($"[NoiseSystem] Noise emitted at {position} with radius {radius}"); OnNoiseEmitted?.Invoke(this, new NoiseEventArgs { Position = position, Radius = radius }); // Find all enemies in range and notify them Collider2D[] hitColliders = Physics2D.OverlapCircleAll(position, radius, _enemyLayer); foreach (Collider2D collider in hitColliders) { var enemy = collider.GetComponent(); if (enemy != null) { enemy.OnNoise(position); if (_debugMode) Debug.Log($"[NoiseSystem] Notified enemy at {collider.transform.position}"); } } } private void OnDrawGizmosSelected() { // Debug visualization in editor if (!_debugMode) return; Gizmos.color = Color.yellow; // This would need to be called from a debug script to visualize noise spheres } } public class NoiseEventArgs : EventArgs { public Vector3 Position { get; set; } public float Radius { get; set; } }