using UnityEngine;

namespace ScrambleKit.FX
{
    [System.Serializable]
    public class FXTrigger
    {
        public Transform SpawnPrefab;
        public string AnimState;
        public string SoundName;
        public float HitStop;
        public float RumbleTime;
        public float RumbleSize;

        public void Trigger(Transform owner)
        {
            if (HitStop != 0)
                HitStopFX.HitStop(HitStop);

            if (RumbleTime != 0)
            {
                if (RumbleSize != 0)
                    CameraFX.Rumble(RumbleTime, RumbleSize);
                else
                    CameraFX.Rumble(RumbleTime);
            }

            if (SpawnPrefab)
            {
                Transform t = GameObject.Instantiate(SpawnPrefab);
                t.position = owner.position;
            }

            if (AnimState != "")
            {
                Animator anim = owner.GetComponent<Animator>();
                if (anim != null)
                    anim.Play(AnimState);
            }

            if(SoundName != "")
            {
                SoundFX.PlaySound(SoundName);
            }
        }

    }
}