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

public class WarningLightScriipt : MonoBehaviour
{
    public bool IsFlickering = false;
    float flicker = 0;

    public AudioSource alarm;
  

    // Update is called once per frame
    void Update()
    {
        flicker = (IsFlickering ? 1 : 0) * (((Mathf.Sin(Time.realtimeSinceStartup*15f)  + 0.5f) * 0.08f ) + 0.2f);
        GetComponent<SpriteRenderer>().color = new Color(1,0,0,flicker);

        if (IsFlickering && alarm.isPlaying == false)
        {
            alarm.loop = true;
            alarm.Play();
        }


        if (!IsFlickering && alarm.isPlaying != false)
        {
            alarm.Stop();
        }
    }
}
