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

public class IkkunaDuunari : MonoBehaviour {

    public GameObject waitfor;
    int state;

    FreqOriginScript freq_source;

    float reso;

    int maxstate;

    public Sprite[] sprites;

	// Use this for initialization
	void Awake () {
        maxstate = 2;
        state = 0;
        freq_source = GameObject.FindGameObjectWithTag("Freq").GetComponent<FreqOriginScript>();
        reso = 1857f;
	}
	
	// Update is called once per frame
	void Update () {
        //print(waitfor.GetComponent<);
		if (waitfor == null && Mathf.Abs(freq_source.Freq() - reso) < 100f && Random.Range(0,50) == 0) {
            Shatter();
        }
	}

    void Shatter() {
        GameObject g = GameObject.Find("venutaustaasia");
        if (state < maxstate) {
            g.GetComponent<SpriteRenderer>().sprite = sprites[++state];
        }
    }
}
