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

public class Shake : MonoBehaviour {

	private Reactor reactor;
	public float shakelimit;
	private RectTransform[] objects;

	public AudioSource meltdownRumble;

	// Use this for initialization
	void Start () {

		objects = FindObjectsOfType<RectTransform> ();

		reactor = FindObjectOfType<Reactor> ();

		meltdownRumble.volume = 0;
	}

	// Update is called once per frame
	void Update () {

		if (reactor.meltdown == false)
		{
			meltdownRumble.volume = reactor.temperature + 0.34f;
			meltdownRumble.volume = Mathf.Clamp (meltdownRumble.volume, 0, 1f);
		}

		if (reactor.temperature > shakelimit)
		{
			foreach (var item in objects)
			{
				//item.localPosition = Vector3.Lerp(item.transform.localPosition, item.transform.position + Random.insideUnitSphere * shakeAmount / 100f, Time.deltaTime * 5f);
				// shakeAmount -= Time.deltaTime * decreaseTime;

				if(item.tag == "shakeable")
					item.anchoredPosition = item.anchoredPosition + Random.insideUnitCircle * reactor.temperature;
			}

			if (reactor.meltdown == true)
				meltdownRumble.volume -= Time.deltaTime * 0.5f;

			else if(reactor.meltdown == false)
				meltdownRumble.volume *= 1.5f;


				
		}
	}
}
