using UnityEngine;
using System.Collections;

public class MovingPlatform : MonoBehaviour {
    public float maxHeight;
    public float minHeight;
    public float speed;
    public float fadeSpeed;
    private bool goingUp;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        if (goingUp)
            transform.Translate(Vector3.up * Time.deltaTime * speed);
        else
            transform.Translate(Vector3.down * Time.deltaTime * speed);

        if (transform.position.y > maxHeight && goingUp)
            goingUp = false;
        if (transform.position.y < minHeight && !goingUp)
            goingUp = true;
        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
        {
            if(renderer.material.color.a < 1.01f)
                renderer.material.color = new Color(0, 0, 0, renderer.material.color.a + Time.deltaTime * fadeSpeed);
        }
        else
        {
            if(renderer.material.color.a > -0.1f)
                renderer.material.color = new Color(0, 0, 0, renderer.material.color.a - Time.deltaTime * fadeSpeed);
        }
	}
}
