using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;

public class UI_Screamometer : MonoBehaviour {


	public Image imageFill;
	private GameObject audioInputObject0;
	private GameObject audioInputObject1;
	private MicrophoneInput micIn0;
	private MicrophoneInput micIn1;

	// Use this for initialization
	void Start () {
		imageFill = GetComponent <Image> ();
		audioInputObject0 = GameObject.Find ("MicInput0");
		micIn0 = (MicrophoneInput) audioInputObject0.GetComponent("MicrophoneInput");
		audioInputObject1 = GameObject.Find ("MicInput1");
		micIn1 = (MicrophoneInput) audioInputObject1.GetComponent("MicrophoneInput");
	}
	
	// Update is called once per frame
	void Update () {
		if (tag == "UI_Player1") {
			if (gameObject.name == "ImageMicInTest0") {
				imageFill.fillAmount = micIn0.loudness;
			} else {
				if (micIn0.loudness > 0.15f) {
					imageFill.fillAmount = micIn0.frequency / 300;
				}
			}
		} else if (tag == "UI_Player2") {
			if (gameObject.name == "ImageMicInTest1") {
				imageFill.fillAmount = micIn1.loudness;
			} else {
				if (micIn1.loudness > 0.15f) {
					imageFill.fillAmount = micIn1.frequency / 300;
					}
			}
		}else 
			imageFill.fillAmount = micIn0.loudness * 0.75f + micIn1.loudness * 0.75f;
	}
}
