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

// octave over pillar

public class VaseBreakScript : FreqReactorScript {

    public GameObject mypillar;
    FreqOriginScript freq_source;
    public Sprite breaksprite;

	// Use this for initialization
	void Start () {
        resonance_note = //mypillar.GetComponent<FreqReactorScript>().resonance_note + 19f;
            Random.Range(16f, 19f);
        resonance_frequency = Tools.Note_To_Freq(resonance_note);
        freq_source = GameObject.FindGameObjectWithTag("Freq").GetComponent<FreqOriginScript>();
	}
	
	// Update is called once per frame
	void Update () {
        if (freq_source == null) return;
		if (Mathf.Abs(Tools.Freq_To_Note(freq_source.Freq())-resonance_note) < 1) {
            if (Random.Range(0, 25) == 0) Break();
        }
	}
    void Break() {
        GetComponent<SpriteRenderer>().sprite = breaksprite;
        Destroy(this);
    }
    void LateUpdate() {
        transform.localEulerAngles = new Vector3(0, 0, transform.localEulerAngles.z);
    }
}
