using UnityEngine;
using System.Collections;

public class SniperEnemy : MonoBehaviour
{
    Transform m_lightGlint;
    float m_glintAmount;
    bool m_glintScope;

    float m_glintTimer;

	// Use this for initialization
	void Start ()
    {
        m_lightGlint = transform.Find("ScopeLight");
        m_lightGlint.light.intensity = 0.0f;

        m_glintTimer = 0;
	}
	
	// Update is called once per frame
	void Update ()
    {
        m_glintTimer += Time.deltaTime * (Random.value+0.5f);
        if (m_glintTimer > 10.0f)
        {
            m_glintScope = true;
            m_glintTimer = 0.0f;
        }

        // Glint the scope when told to
        if (m_glintScope)
        {
            m_glintAmount += 5 * Time.deltaTime;
            if (m_glintAmount > 1)
            {
                m_glintAmount = 1.0f;
                m_glintScope = false;
            }
        }
        else
        {
            m_glintAmount -= 5 * Time.deltaTime;
            if (m_glintAmount < 0)
            {
                m_glintAmount = 0.0f;
            }
        }
        m_lightGlint.light.intensity = m_glintAmount*2.0f;
    }
}
