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

public class TriggerPlatform : MonoBehaviour {

	public GameObject platform;
	public GameObject missingCircuitCube;

	public Transform startMarker;
	public Transform endMarker;
	public float speed = 1.0F;
	private float startTime;
	private float journeyLength;
	private int state;

	// Use this for initialization
	void Start () {
		state = 0;
		startTime = Time.time;
		journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
	}
	
	// Update is called once per frame
	void Update () {
		if (state == 1) {
			float distCovered = (Time.time - startTime) * speed;
			float fracJourney = distCovered / journeyLength;
			platform.transform.position = Vector3.Lerp (startMarker.position, endMarker.position, fracJourney);	
		}
	}
	 
	void OnTriggerEnter(Collider other){
		if (other.gameObject == missingCircuitCube) {
			missingCircuitCube.GetComponent<CircuitCube> ().state = 1;
			state = 1;
		}

	}
}
