sea-battle/Assets/Scripts/EffectManager.cs
2026-01-09 08:45:22 +03:00

49 lines
1.3 KiB
C#

using UnityEngine;
public class EffectManager : MonoBehaviour
{
public static EffectManager Instance;
[Header("Text Effects")]
public GameObject[] hitTextEffects; // Íàäïèñè ïðè ïîïàäàíèè
public GameObject[] missTextEffects; // Íàäïèñè ïðè ïðîìàõå
public GameObject[] shotTextEffects; // Íàäïèñè ïðè âûñòðåëå
private void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
}
// Íàäïèñü ïîïàäàíèÿ
public GameObject PlayHitText(Vector3 position)
{
return SpawnRandomEffect(hitTextEffects, position);
}
// Íàäïèñü ïðîìàõà
public GameObject PlayMissText(Vector3 position)
{
return SpawnRandomEffect(missTextEffects, position);
}
// Íàäïèñü âûñòðåëà
public void PlayShotText(Vector3 position)
{
SpawnRandomEffect(shotTextEffects, position);
}
private GameObject SpawnRandomEffect(GameObject[] prefabs, Vector3 position)
{
if (prefabs == null || prefabs.Length == 0) return null;
int index = Random.Range(0, prefabs.Length);
GameObject prefab = prefabs[index];
if (prefab == null) return null;
GameObject effect = Instantiate(prefab, position, Quaternion.identity);
Destroy(effect, 2f);
return effect;
}
}