IEnumerator ShootEnemy(Transform _enemy)
    {
        if (!shootingLights)
        {
            weapon.StopCoroutine("TrailingEffectOn");
            if (weapon.lightningCoroutine != null)
            {
                weapon.StopCoroutine(weapon.lightningCoroutine);
            }
            Destroy(weapon.particleEffect);
            weapon.StartCoroutine("TrailingEffectOn", switchTime);
            weapon.StartCoroutine(weapon.LightningEffectOn(switchTime, false));
        }
        shootingLights = true;
        _enemy.GetComponent <EnemyController>().gettingShoot = true;
        EnemyWeapon _enemyWeapon = _enemy.GetComponentInChildren <EnemyWeapon>();

        if (_enemyWeapon.lightningCoroutine != null)
        {
            _enemyWeapon.StopCoroutine(_enemyWeapon.lightningCoroutine);
        }
        _enemyWeapon.StopCoroutine("TrailingEffectOn");
        _enemyWeapon.StopCoroutine("TrailingEffectOff");
        SoundManager.Instance.GunshotStop();
        Destroy(_enemyWeapon.particleEffect);
        _enemy.GetComponent <EnemyController>().controlled = true;
        _enemy.GetComponent <Enemy>().SetDirectionalInput(Vector2.zero);
        _enemy.GetComponent <EnemyInput>().enabled = false;
        yield return(new WaitForSeconds(switchTime));

        if (_enemy && _enemy.parent.gameObject)
        {
            _enemy.GetComponent <EnemyController>().Kill();
        }
        weapon.StopCoroutine("TrailingEffectOn");
        if (weapon.lightningCoroutine != null)
        {
            weapon.StopCoroutine(weapon.lightningCoroutine);
        }
        weapon.StopCoroutine("LightningEffectOn");
    }
    IEnumerator HuntTraitor()
    {
        while (true)
        {
            Transform _enemyTarget = null;

            if (!controlled && !changingStatus && !shootingLights)
            {
                foreach (GameObject _enemy in GameObject.FindGameObjectsWithTag(Tags.enemy))
                {
                    if (_enemy.GetComponent <EnemyController>().controlled)
                    {
                        _enemyTarget = _enemy.transform;
                        break;
                    }
                }
                if (_enemyTarget != null)
                {
                    if (enemyTarget != null && enemyTarget.parent != _enemyTarget.parent)
                    {
                        StopCoroutine("ShootEnemy");
                        enemyTarget.GetComponent <EnemyController>().gettingShoot = false;
                        enemy.gameObject.GetComponent <Animator>().SetBool("EnemyTraitor", false);
                    }
                    enemyTarget  = _enemyTarget;
                    mChaseTarget = enemyTarget.position;
                    mDirection   = (mChaseTarget - transform.position);

                    if (Mathf.Abs(enemy.transform.position.y - enemyTarget.transform.position.y) > 1.6f)
                    {
                        animator.SetBool("EnemyTraitor", false);
                        shootingLights = false;
                    }

                    bool collidingWithTarget = false;
                    foreach (Collider2D obj in Physics2D.OverlapCircleAll(boxCollider2D.bounds.center, 0.1f))
                    {
                        if (enemyTarget && obj.transform.parent == enemyTarget.parent && enemyTarget.GetComponent <EnemyController>().controlled)
                        {
                            collidingWithTarget = true;
                            break;
                        }
                        else
                        {
                            collidingWithTarget = false;
                        }
                    }

                    if (!enemy.isClimbing && (InLineOfShot(enemyTarget, weaponRange) || collidingWithTarget) && enemy.controller.collisions.below && !changingStatus && !inTransition && !gettingShoot && enemy.gameObject.GetComponent <Animator>().GetBool("EnemyTraitor"))
                    {
                        EnemyController enemyTargetC = enemyTarget.GetComponent <EnemyController>();
                        enemyTargetC.StopCoroutine("ShootEnemy");
                        EnemyWeapon _enemyWeapon = enemyTargetC.GetComponentInChildren <EnemyWeapon>();
                        //Debug.Log(_enemyWeapon.GetType().Equals(typeof(EnemyWeapon)));
                        if (_enemyWeapon.GetType().Equals(typeof(EnemyWeapon)))
                        {
                            _enemyWeapon.enemyControlled.changingStatus = false;
                            _enemyWeapon.enemyControlled.gettingShoot   = false;
                            _enemyWeapon.enemyControlled.StopCoroutine("ConrtolledOn");

                            _enemyWeapon.mLineRenderer.enabled = true;
                            if (_enemyWeapon.lightningCoroutine != null)
                            {
                                _enemyWeapon.StopCoroutine(_enemyWeapon.lightningCoroutine);
                            }
                            _enemyWeapon.StopCoroutine("TrailingEffectOn");
                            _enemyWeapon.StopCoroutine("TrailingEffectOff");
                            Destroy(_enemyWeapon.particleEffect);
                        }
                        if (ranged)
                        {
                            StartCoroutine("ShootEnemy", enemyTarget);
                        }
                        else
                        {
                            StartCoroutine("MeleeAttack", enemyTarget);
                        }
                    }

                    if (shootingLights || gettingShoot || inTransition)
                    {
                        mDirection = Vector2.zero;
                    }

                    if (!changingStatus && player != null)
                    {
                        if (InLineOfSight(player, sightRange) && GameObject.FindGameObjectWithTag(Tags.mainCamera).GetComponent <Collider2D>().bounds.Contains(transform.position + new Vector3(0, 0, -10)) && GameObject.FindGameObjectWithTag(Tags.mainCamera).GetComponent <Collider2D>().bounds.Contains(player.position + new Vector3(0, 0, -10)))
                        {
                            animator.SetBool("PlayerInSight", true);
                            playerInSight = true;
                            mChaseTarget  = player.position;
                        }
                    }

                    enemy.SetDirectionalInput(mDirection.normalized);
                }
                else
                {
                    enemy.gameObject.GetComponent <Animator>().SetBool("EnemyTraitor", false);
                }
            }
            else if (changingStatus || enemy.controlling || gettingShoot || inTransition)
            {
                enemy.SetDirectionalInput(Vector2.zero);
            }

            yield return(null);
        }
    }
 public void StartPatrol()
 {
     //Debug.Log("Start Patrol")
     StopCoroutine("Patrol");
     StopCoroutine("HuntTraitor");
     StopCoroutine("Chase");
     StopCoroutine("RandomlyBark");
     enemy.moveMinSpeed = 2f;
     enemyTarget        = null;
     animator.SetBool("PlayerInSight", false);
     animator.SetBool("EnemyTraitor", false);
     playerInSight = false;
     weapon.StopCoroutine("TrailingEffectOn");
     if (weapon.lightningCoroutine != null)
     {
         weapon.StopCoroutine(weapon.lightningCoroutine);
     }
     Destroy(weapon.particleEffect);
     if (flipStartDir)
     {
         setDestination(endPoint);
     }
     weapon.transform.parent.rotation = Quaternion.Euler(0f, 0f, transform.localScale.x > 0?73.4f:-73.4f);
     if (isChasing)
     {
         SoundManager.Instance.PlayNormalSoundtrack();
         isChasing = false;
     }
     StartCoroutine("Patrol");
     weapon.mLineRenderer.material = weapon.idleMaterial;
 }