using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CatHitScript : MonoBehaviour
{

    public AudioSource audioSource;
    public AudioClip[] slap;

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }

    public void PlayHitScript()
    {
        if (slap != null && slap.Length > 0)
        {
            int CheckIndex = Random.Range(0, slap.Length - 1);
            var sfx = slap[CheckIndex];

            if (sfx && audioSource) {

                audioSource.PlayOneShot(sfx);
            }
        }
    }

    public void Death()
    {
        var audioplay = GetComponents<AudioSource>();
        foreach( var a in audioplay) {
            a.Stop();
        }
        var cats = FindObjectsOfType(typeof(catBody));
        foreach (var cc in cats) {
            var c = cc as catBody;
            c.GetComponent<Animator>().enabled = false;
            c.transform.parent.GetComponent<CatBasicAIBehaviour>().enabled = false;
        }
        Invoke("AfterDeath", 2);
    }

    public void AfterDeath()
    {
        var level = FindObjectOfType(typeof(LevelManager));
        var lev = level as LevelManager;
        lev.loseGame();
    }
}
