// Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.L))
        {
            StartAutoFire();
        }

        if (Time.realtimeSinceStartup < LastFireTime + 1f / Frequency)
        {
            return;
        }
        LastFireTime = Time.realtimeSinceStartup;

        if (!IsAutoFire)
        {
            return;
        }

        if (Time.realtimeSinceStartup - TimeStartFire > TimeFireVal)
        {
            return;
        }

        GameObject  obj        = (GameObject)Instantiate(AmmoNpcPrefab, AmmoSpawnPoint.position, AmmoSpawnPoint.rotation);
        NpcAmmoCtrl AmmoScript = obj.GetComponent <NpcAmmoCtrl>();

        AmmoScript.SetIsAimPlayer(IsAimPlayer);
        AmmoScript.SetIsAimFeiJiPlayer(IsAimPlayer);
        Transform tran = obj.transform;

        tran.parent = XkGameCtrl.MissionCleanup;

        if (AmmoLiZi != null)
        {
            obj         = (GameObject)Instantiate(AmmoLiZi, AmmoSpawnPoint.position, AmmoSpawnPoint.rotation);
            tran        = obj.transform;
            tran.parent = XkGameCtrl.MissionCleanup;
            XkGameCtrl.CheckObjDestroyThisTimed(obj);
        }
    }
    IEnumerator SpawnDuoPaoAmmo()
    {
        if (!IsDouGuanDaPao)
        {
            yield break;
        }

        int countMax = SpawnAmmoPoint.Length;
        int count    = countMax;

        do
        {
            if ((JiFenJieMianCtrl.GetInstance() != null && JiFenJieMianCtrl.GetInstance().GetIsShowFinishTask()) ||
                IsDeathNpc ||
                GameOverCtrl.IsShowGameOver)
            {
                yield break;
            }

            count--;
            PlayAudioCannonFire();

            GameObject obj = GetNpcAmmoFromList(SpawnAmmoPoint[count]);
            if (obj == null)
            {
                yield break;
            }

            NpcAmmoCtrl AmmoScript = obj.GetComponent <NpcAmmoCtrl>();
            if (IsHiddenAmmoSpawnPoint)
            {
                if ((count + 1) == countMax)
                {
                    XKTriggerStopMovePlayer.SetKaQiuShaAmmoTrInfo(AmmoScript);
                }
                AmmoScript.SetIsCannotAddNpcAmmoList();
            }
            AmmoScript.SetIsAimPlayer(false);
            AmmoScript.SetIsAimFeiJiPlayer(false);
            Transform tran = obj.transform;
            tran.parent = XkGameCtrl.NpcAmmoArray;
            if (IsHiddenAmmoSpawnPoint)
            {
                SpawnAmmoPoint[count].gameObject.SetActive(false);
            }
            else
            {
                if (!SpawnAmmoPoint[count].gameObject.activeSelf)
                {
                    SpawnAmmoPoint[count].gameObject.SetActive(true);
                }
            }

            if (DaPaoAmmoLiZiObj[count] == null && DaPaoAmmoLiZi != null)
            {
                obj  = (GameObject)Instantiate(DaPaoAmmoLiZi, SpawnAmmoPoint[count].position, SpawnAmmoPoint[count].rotation);
                tran = obj.transform;
                DaPaoAmmoLiZiObj[count] = obj;
                XkGameCtrl.CheckObjDestroyThisTimed(obj);

                if (IsHiddenAmmoSpawnPoint)
                {
                    tran.parent = XkGameCtrl.NpcAmmoArray;
                }
                else
                {
                    tran.parent = SpawnAmmoPoint[count];
                }
            }

            yield return(new WaitForSeconds(TimeAmmoUnit));

            if (!IsDoFireAnimation || IsStopAnimation)
            {
                yield break;
            }

            if (count <= 0)
            {
                yield return(new WaitForSeconds(TimeAmmoWait));

                if (!IsDoFireAnimation || IsStopAnimation || IsHiddenAmmoSpawnPoint)
                {
                    if (IsHiddenAmmoSpawnPoint)
                    {
                        IsDonnotSpawnAmmo = true;
                    }
                    yield break;
                }
                else
                {
                    count = countMax;
                    continue;
                }
            }
        } while (count > 0);
    }
    IEnumerator PlayPaoGuanAnimation()
    {
        int   count         = 0;
        int   maxCount      = 1;
        float speed         = PaoGuanZhenFu / maxCount;
        bool  isBackPaoGuan = false;
        bool  isFireAmmo    = false;

        IsPlayPaoGuanAnimation = true;
        do
        {
//			if (JiFenJieMianCtrl.GetInstance().GetIsShowFinishTask()
//			    || IsDeathNpc
//			    || GameOverCtrl.IsShowGameOver) {
//				yield break;
//			}

            if (IsStopAnimation)
            {
                yield return(new WaitForSeconds(0.3f));

                continue;
            }

            if (!isBackPaoGuan)
            {
                PaoGuan.position -= PaoGuan.forward * speed;
                count++;
                if (count >= maxCount)
                {
                    isBackPaoGuan = true;
                }

                if (count == 1 && !isFireAmmo)
                {
                    isFireAmmo = true;
                    PlayAudioCannonFire();

                    PlayerAmmoCtrl ammoPlayerScript = DaPaoAmmo.GetComponent <PlayerAmmoCtrl>();
                    if (ammoPlayerScript != null && !XkGameCtrl.GetInstance().IsCartoonShootTest)
                    {
                        yield break;
                    }

                    GameObject obj = GetNpcAmmoFromList(SpawnAmmoPoint[0]);
                    if (obj == null)
                    {
                        yield break;
                    }

                    NpcAmmoCtrl AmmoScript = obj.GetComponent <NpcAmmoCtrl>();
                    Transform   tran       = obj.transform;
                    tran.parent = XkGameCtrl.NpcAmmoArray;
                    if (AmmoScript != null)
                    {
                        AmmoScript.SetIsAimPlayer(false);
                        AmmoScript.SetIsAimFeiJiPlayer(false);
                    }
                    else
                    {
                        PlayerAmmoCtrl ammoScript = obj.GetComponent <PlayerAmmoCtrl>();
                        if (ammoScript != null)
                        {
                            Vector3 startPos    = tran.position;
                            Vector3 firePos     = tran.position;
                            Vector3 ammoForward = tran.forward;
                            firePos = Random.Range(300f, 400f) * ammoForward + startPos;
                            float      fireDisVal = Vector3.Distance(firePos, startPos);
                            RaycastHit hit;
                            LayerMask  FireLayer = XkGameCtrl.GetInstance().PlayerAmmoHitLayer;
                            if (Physics.Raycast(startPos, ammoForward, out hit, fireDisVal, FireLayer.value))
                            {
                                //Debug.Log("npc fire PlayerAmmo, fire obj -> "+hit.collider.name);
                                firePos = hit.point;
                                XKNpcHealthCtrl healthScript = hit.collider.GetComponent <XKNpcHealthCtrl>();
                                if (healthScript != null)
                                {
                                    healthScript.OnDamageNpc(ammoScript.AmmoType, PlayerEnum.Null);
                                }

                                BuJiBaoCtrl buJiBaoScript = hit.collider.GetComponent <BuJiBaoCtrl>();
                                if (buJiBaoScript != null)
                                {
                                    buJiBaoScript.RemoveBuJiBao(PlayerEnum.Null);                                     //buJiBaoScript
                                }
                            }
                            ammoScript.StartMoveAmmo(firePos, PlayerEnum.Null, AmmoMovePath);
                        }
                    }

                    if (DaPaoAmmoLiZiObj[0] == null && DaPaoAmmoLiZi != null)
                    {
                        obj  = (GameObject)Instantiate(DaPaoAmmoLiZi, SpawnAmmoPoint[0].position, SpawnAmmoPoint[0].rotation);
                        tran = obj.transform;
                        DaPaoAmmoLiZiObj[0] = obj;
                        XkGameCtrl.CheckObjDestroyThisTimed(obj);

                        if (!SpawnAmmoPoint[0].gameObject.activeSelf)
                        {
                            SpawnAmmoPoint[0].gameObject.SetActive(true);
                        }
                        tran.parent = SpawnAmmoPoint[0];
                    }
                }
            }
            else
            {
                PaoGuan.position += PaoGuan.forward * speed;
                count--;
                if (count <= 0)
                {
                    //break;
                    IsPlayPaoGuanAnimation = false;
                    isBackPaoGuan          = false;
                    isFireAmmo             = false;
                    count = 0;
                    if (IsDoFireAnimation)
                    {
                        yield return(new WaitForSeconds(TimeDanGuanFire));

                        IsPlayPaoGuanAnimation = true;
                        continue;
                    }
                }
            }
            yield return(new WaitForSeconds(PaoGuanShenSuoSD));
//			Debug.Log("dp****************"+Time.deltaTime);
        } while (IsDoFireAnimation);
    }