void Start()
    {
        m_rigb     = GetComponent <Rigidbody>();
        m_players  = FindObjectsOfType <PlayerData>();
        m_renderer = GetComponent <Renderer>();

        Transform[] refrences = gameObject.GetComponentsInChildren <Transform>();

        for (int z = 0; z < refrences.Length; z++)
        {
            if (refrences[z].tag == "Attack")
            {
                m_attack = refrences[z].gameObject;
            }
        }

        if (m_attack == null)
        {
            Debug.Log("-----Error attack refrence not found!------");
        }

        m_attack.SetActive(false);

        m_attackDelayTimer    = new Timer();
        m_attackActiveTimer   = new Timer();
        m_attackRecoveryTimer = new Timer();

        m_attackDelayTimer.m_time    = m_attackDelay;
        m_attackActiveTimer.m_time   = m_attackActive;
        m_attackRecoveryTimer.m_time = m_attackRecovery;

        m_actionState        = E_ActionState.PATROLLING;
        m_PlayerLastPosition = new Vector3(0.0f, -11.0f, 0.0f);
        m_patrollingCenter   = gameObject.transform.position;
    }
    void Movement()
    {
        if (m_actionState == E_ActionState.FOLOWING_PLAYER)
        {
            if (gameObject.transform.position.x > m_targate.GetCenterTransform().x)
            {
                m_rigb.velocity = new Vector3(-3.0f, m_rigb.velocity.y);
                m_faceingLeft   = true;
            }
            else
            {
                m_rigb.velocity = new Vector3(3.0f, m_rigb.velocity.y);
                m_faceingLeft   = false;
            }
        }
        else if (m_actionState == E_ActionState.LOOKING_FOR_PLAYER)
        {
            if (Mathf.Abs(gameObject.transform.position.x - m_PlayerLastPosition.x) < 0.1f)
            {
                m_PlayerLastPosition.y = -11.0f;
            }

            if (gameObject.transform.position.x > m_PlayerLastPosition.x)
            {
                m_rigb.velocity = new Vector3(-3.0f, m_rigb.velocity.y);
                m_faceingLeft   = true;
            }
            else
            {
                m_rigb.velocity = new Vector3(3.0f, m_rigb.velocity.y);
                m_faceingLeft   = false;
            }
        }
        else if (m_actionState == E_ActionState.PATROLLING)
        {
            if (gameObject.transform.position.x > m_patrollingCenter.x + 1.0f)
            {
                m_patrollingLeft = true;
            }
            else if (gameObject.transform.position.x < m_patrollingCenter.x - 1.0f)
            {
                m_patrollingLeft = false;
            }

            m_rigb.velocity = new Vector3(m_patrollingLeft ? -1.0f : 1.0f, m_rigb.velocity.y);
        }
        else if (m_actionState == E_ActionState.NEXT_TO_PLAYER)
        {
            if (!m_attackDelayTimer.m_playing)
            {
                m_attackDelayTimer.Play();
            }

            if (m_attackDelayTimer.m_completed)
            {
                m_actionState = E_ActionState.ATTACKING;
                m_attackDelayTimer.Stop();
                m_attackActiveTimer.Play();

                m_attack.SetActive(true);
            }
        }
        else if (m_actionState == E_ActionState.ATTACKING)
        {
            m_attack.transform.Rotate(0.0f, 30.0f, 0.0f);

            if (m_attackActiveTimer.m_completed)
            {
                m_attackActiveTimer.Stop();

                m_attack.SetActive(false);

                m_attackRecoveryTimer.Play();
            }

            if (m_attackRecoveryTimer.m_completed)
            {
                m_attackRecoveryTimer.Stop();

                m_actionState = E_ActionState.PATROLLING;
            }
        }
    }
    void CheckForPlayer()
    {
        E_ActionState m_previousState = m_actionState;

        m_actionState             = E_ActionState.NULL;
        m_targate                 = null;
        m_renderer.material.color = Color.green;

        for (int z = 0; z < m_players.Length; z++)
        {
            float distance = Mathf.Abs(gameObject.transform.position.x - m_players[z].GetCenterTransform().x);

            if (m_players[z].tag == "Player" && distance <= 1.25f)
            {
                m_targate                 = m_players[z];
                m_actionState             = E_ActionState.NEXT_TO_PLAYER;
                m_renderer.material.color = Color.magenta;

                break;
            }
            else if (m_players[z].tag == "Player" && distance <5.0f && distance> 1.5f)
            {
                RaycastHit hitData;

                Physics.Raycast(transform.position, m_players[z].GetCenterTransform() - transform.position, out hitData);

                if (hitData.transform == m_players[z].transform)
                {
                    Debug.DrawRay(transform.position, m_players[z].GetCenterTransform() - transform.position, Color.green);

                    m_targate                 = m_players[z];
                    m_PlayerLastPosition      = m_players[z].GetCenterTransform();
                    m_actionState             = E_ActionState.FOLOWING_PLAYER;
                    m_renderer.material.color = Color.red;
                }
                else
                {
                    Debug.DrawRay(transform.position, m_players[z].GetCenterTransform() - transform.position, Color.red);
                }
            }
        }

        if (m_actionState == E_ActionState.NULL && m_PlayerLastPosition.y != -11.0f)
        {
            m_actionState             = E_ActionState.LOOKING_FOR_PLAYER;
            m_renderer.material.color = Color.yellow;
        }

        if (m_actionState == E_ActionState.NULL)
        {
            if (m_previousState != E_ActionState.PATROLLING)
            {
                m_patrollingCenter = gameObject.transform.position;
            }

            m_actionState = E_ActionState.PATROLLING;
        }

        if (m_previousState == E_ActionState.NEXT_TO_PLAYER && !(m_actionState == E_ActionState.NEXT_TO_PLAYER /*|| m_actionState == E_ActionState.ATTACKING*/))
        {
            m_attackDelayTimer.m_completed = false;
            m_attackDelayTimer.m_playing   = false;
        }
    }