using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScanAnim : MonoBehaviour
{

    #region Private Variables
    private Material myMat;
    private bool flag;
    #endregion

    #region Public Variables
    public float scanSpeed = 1;
    #endregion

    #region Unity Methods
    void Start()
    {
        myMat = GetComponent<MeshRenderer>().material;

        float deltaAngle = myMat.GetFloat("_DeltaAngle");
        myMat.SetFloat("_MaxAngle", deltaAngle);
    }

    void Update()
    {
        float maxAngle = myMat.GetFloat("_MaxAngle");
        //控制扇形顺时针扫描
        if (maxAngle < 180 && !flag)
        {
            myMat.SetFloat("_MaxAngle", maxAngle + scanSpeed);
            if (maxAngle + scanSpeed >= 180)
            {
                flag = !flag;
            }
        }
        //控制扇形逆时针扫描
        if (maxAngle > 0 && flag)
        {
            myMat.SetFloat("_MaxAngle", maxAngle - scanSpeed);
            if (maxAngle - scanSpeed <= myMat.GetFloat("_DeltaAngle"))
            {
                flag = !flag;
            }
        }
    }
    #endregion
}