using UnityEngine;
using System.Collections;

public class PlatformAudio : MonoBehaviour {

	public GameObject audioInputObject;
	MicrophoneInput micIn;
	Vector3 startPosV;
	Vector3 startPosH;
	Vector3 endPos;
	Vector3 posV;
	Vector3 posH;

	public bool vertical;

	// Use this for initialization
	void Start () {
		startPosV = transform.position;
		startPosH = transform.position;
		micIn = (MicrophoneInput)audioInputObject.GetComponent("MicrophoneInput");

	}

	// Update is called once per frame
	void Update () {
		
		if (vertical) {
			posV = startPosV;
			if (micIn.loudness > 0.15f && micIn.frequency > 80f) {
				float newY = startPosV.y;
				newY -= micIn.frequency * 0.05f;
				posV = new Vector3 (startPosV.x, newY, startPosV.z);
				//Debug.Log (newY);
			}
			transform.position = posV;
		} else {
			posH = startPosH;
			if (micIn.loudness > 0.15f) {
				float newX = startPosH.x;
				newX -= micIn.frequency * 0.1f;
				posH = new Vector3 (newX, startPosH.y, startPosH.z);
				 
				//Debug.Log (newX);
			}
			transform.position = posH;
		}
			
	}
}
