using UnityEngine;
using System.Collections;

public class WallSegment : MonoBehaviour {

    public Collider wallCollider;
    public Transform colliderScale;

    public float lifetimeSeconds = 10F;

    private Transform tracerReferencePoint;
    public Transform TracerReferencePoint {
        set { tracerReferencePoint = value; }
    }

    private bool growing = true;
    public void StopGrowing() {
        Update();
        growing = false;
        StartCoroutine(DestroyAfterLifetime());
    }

    public IEnumerator DestroyAfterLifetime() {
        yield return new WaitForSeconds(lifetimeSeconds);
        Destroy(this.gameObject);
    }

    private float distance = 0;
    public float Distance {
        get { return distance; }
    }

    void Update() {
        if (growing) {
            distance = Vector3.Distance(
                    transform.position,
                    tracerReferencePoint.position);
            Vector3 scale = colliderScale.localScale;
            scale.z = distance;
            colliderScale.localScale = scale;
        }
    }
}
