using UnityEngine;
using System.Collections;

public class BunScript : MonoBehaviour {

	GameObject object1;
	GameObject object2;
	int end_time_1;
	int end_time_2;

	// Use this for initialization
	void Start () {
		object1 = null;
		object2 = null;
		end_time_1 = 0;
		end_time_2 = 0;
	}
	
	// Update is called once per frame
	void Update () {

		if(object1 != null){
			float timeLeft_1 = end_time_1 - Time.time;
			if(timeLeft_1 < 0f){
				object1.GetComponent<Movement>().speed = 20f;
				end_time_1 = 0;
			}
		}
		if(object2 != null){
			float timeLeft_2 = end_time_2 - Time.time;
			if(timeLeft_2 < 0){
				object2.GetComponent<Movement>().speed = 20f;
				end_time_2 = 0;
			}
		}
	
	}

	void OnTriggerEnter(Collider col){
		if(col.gameObject.tag == "Player"){
			col.gameObject.GetComponent<Movement>().speed = col.gameObject.GetComponent<Movement>().speed * 0.5f;
			if(object1 != null && end_time_1 != 0){
				object1 = col.gameObject;
				end_time_1 = (int)Time.time + 10;
			}
			else {
				object2 = col.gameObject;
				end_time_2 = (int)Time.time + 10;
			}
		}

	}
}
