using UnityEngine;
using ScrambleKit.FX;

public class CryoPod : MonoBehaviour 
{

    public Transform Prefab;
    public Sprite OpenedSprite;
    public FXTrigger OpeningFX;
    public Vector3 SpawnOffset;

    private bool open = false;

    void Start()
    {
        Score.HumansTotal++;
    }

    void OnCollisionEnter2D(Collision2D c)
    {
        if (open)
            return;

        if (c.transform.GetComponent<Human>() == null)
            return;

        Open();
    }

    private void Open()
    {
        open = true;
        ScrambleKit.FX.SoundFX.PlaySound("OpenCryo");
        GetComponent<SpriteRenderer>().sprite = OpenedSprite;
        OpeningFX.Trigger(transform);
        Instantiate(Prefab, transform.position + SpawnOffset, Quaternion.identity);
    }

}
