using UnityEngine;
using System.Collections;

public class WallSegment : MonoBehaviour {

    public Collider wallCollider;

    public float lifetimeSeconds = 10F;

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

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

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

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