using UnityEngine;
using System.Collections;

public class FogScript : MonoBehaviour {

    public float lifeTime;
    public float lifeTimer;
    public float moveSpeed;
    public float appearSpeed;
    public float fadeTime;
    public float max_opacity;

    SpriteRenderer sr;

    bool appeared = false;

	// Use this for initialization
	void Start () {
        sr = GetComponent<SpriteRenderer>();
        Color c = sr.color;
        sr.color = new Color(c.r, c.g, c.b, 0f);
        transform.localScale = new Vector3(Random.Range(1f, 2f), 1f, 1f);
        transform.localScale *= Random.Range(0.5f, 1.2f);
    }
	
	// Update is called once per frame
	void Update () {
        
        if(appeared == false)
        {
            Color c = sr.color;
            sr.color = new Color(c.r, c.g, c.b, c.a + appearSpeed);
            if(sr.color.a > max_opacity) { appeared = true; }
        }

        if(lifeTime - lifeTimer < fadeTime)
        {
            Color c = sr.color;
            sr.color = new Color(c.r, c.g, c.b, c.a + -((max_opacity / fadeTime)/30));
        }

        lifeTimer += Time.deltaTime;
        if(lifeTimer > lifeTime)
        {
            Destroy(gameObject);
        }

        transform.position += Vector3.right * moveSpeed;
	}
}
