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

public class BoxColliderExpansion : MonoBehaviour {

	public BoxCollider myCollider;
	public BoxColliderExpansion boxColliderExpansion;
	public float boxOriginalExpansionSpeed = 20.0f;
	public float boxExpansionSpeed = 20.0f;
	public float boxOriginalSlowDownSpeed = 1.0f;
	public float boxSlowDownSpeed = 1.0f;
	public float boxOriginalSlowDownAcc = 1.0f;
	public float boxSlowDownAcc = 1.0f;
	public float boxOriginalRetriggerSpeed = 3.0f;
	public float boxRetriggerSpeed = 3.0f;
	public string primeBoxColliderTag = "Prime Box Collider Expansion";

	void Start () {
		if (gameObject.tag == primeBoxColliderTag) {
			boxColliderExpansion = gameObject.GetComponent<BoxColliderExpansion> ();
			boxColliderExpansion.enabled = false;
		} else {
			myCollider = gameObject.GetComponent (typeof(BoxCollider)) as BoxCollider;
			myCollider.size = new Vector3(1.0f, 1.0f, 1.0f);
		}
	}

	void Update () {
		if (boxExpansionSpeed >= 0) {
			myCollider.transform.localScale += new Vector3((boxExpansionSpeed * Time.deltaTime),
				(boxExpansionSpeed * Time.deltaTime),
				(boxExpansionSpeed * Time.deltaTime));
			
			boxExpansionSpeed -= (boxSlowDownSpeed * Time.deltaTime);
			boxSlowDownSpeed += boxSlowDownAcc * Time.deltaTime;
		}
//		else Destroy (gameObject);
		if (boxSlowDownSpeed >= boxRetriggerSpeed) {
			myCollider.transform.localScale = new Vector3(40.0f, 1.0f, 1.0f);
			boxExpansionSpeed = boxOriginalExpansionSpeed;
			boxSlowDownSpeed = boxOriginalSlowDownSpeed;
	}
	}
}
