using UnityEngine;

public class BreathController : MonoBehaviour {

    public GameObject breathPrefab;
    private AudioSource audioSource;

    void Start () {
        PubSubService<AIStateChanged>.GetInstance().Suscribe(HandleAIStateChanged);
        this.audioSource = this.GetComponent<AudioSource>();
        if (this.audioSource == null || breathPrefab == null)
            throw new System.Exception("Fix dependencies (audiosources and prefab)");
    }


    void HandleAIStateChanged(AIStateChanged _state)
    {
        switch (_state.state)
        {
            case AIAction.patrol:
                Instantiate(breathPrefab);
                break;
        }
        this.audioSource.Play();
    }

    private void OnDestroy()
    {
        PubSubService<AIStateChanged>.GetInstance().Unsuscribe(HandleAIStateChanged);
    }
}
