void StartSpawnNpcAmmo() { if (AudioNpcFire != null) { if (AudioNpcFire.isPlaying) { AudioNpcFire.Stop(); } AudioNpcFire.Play(); } GameObject obj = null; Transform tran = null; if (AmmoLiZiPrefab != null) { obj = SpawnParticleCom.SpawnParticleObject(AmmoLiZiPrefab, AmmoSpawnTran.position, AmmoSpawnTran.rotation); if (obj.transform.parent != XkGameCtrl.NpcAmmoArray) { obj.transform.parent = XkGameCtrl.NpcAmmoArray; } } PlayerAmmoCtrl ammoPlayerScript = AmmoPrefab.GetComponent <PlayerAmmoCtrl>(); if (ammoPlayerScript != null && !XkGameCtrl.GetInstance().IsCartoonShootTest) { return; } obj = GetNpcAmmoFromList(AmmoSpawnTran); if (obj == null) { return; } tran = obj.transform; tran.parent = XkGameCtrl.NpcAmmoArray; NpcAmmoCtrl AmmoScript = obj.GetComponent <NpcAmmoCtrl>(); if (AmmoScript != null) { AmmoScript.SetNpcScriptInfo(NpcScript); AmmoScript.SetIsAimFeiJiPlayer(IsAimFeiJiPlayer); } 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); } } }
void StartSpawnNpcAmmo() { if (XkGameCtrl.CheckNpcIsMoveToCameraBack(transform)) { return; } if (AudioNpcFire != null) { if (AudioNpcFire.isPlaying) { AudioNpcFire.Stop(); } AudioNpcFire.Play(); } GameObject obj = null; Transform tran = null; if (AmmoLiZiPrefab != null && AmmoLiZiObj == null) { obj = (GameObject)Instantiate(AmmoLiZiPrefab, AmmoSpawnTran.position, AmmoSpawnTran.rotation); tran = obj.transform; tran.parent = XkGameCtrl.NpcAmmoArray; AmmoLiZiObj = obj; XkGameCtrl.CheckObjDestroyThisTimed(obj); } if (AmmoPrefab == null) { return; } PlayerAmmoCtrl ammoPlayerScript = AmmoPrefab.GetComponent <PlayerAmmoCtrl>(); if (ammoPlayerScript != null && !XkGameCtrl.GetInstance().IsCartoonShootTest) { return; } obj = GetNpcAmmoFromList(AmmoSpawnTran); if (obj == null) { return; } tran = obj.transform; tran.parent = XkGameCtrl.NpcAmmoArray; NpcAmmoCtrl AmmoScript = obj.GetComponent <NpcAmmoCtrl>(); if (AmmoScript != null) { AmmoScript.SetNpcScriptInfo(NpcScript); AmmoScript.SetIsAimFeiJiPlayer(IsAimFeiJiPlayer); for (int i = 0; i < AmmoSpawnArray.Length; i++) { if (AmmoSpawnArray[i] != null) { obj = (GameObject)Instantiate(AmmoPrefab, AmmoSpawnArray[i].position, AmmoSpawnArray[i].rotation); tran = obj.transform; tran.parent = XkGameCtrl.NpcAmmoArray; AmmoScript = obj.GetComponent <NpcAmmoCtrl>(); AmmoScript.SetNpcScriptInfo(NpcScript); AmmoScript.SetIsAimFeiJiPlayer(IsAimFeiJiPlayer); } } } 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("Unity:"+"npc fire PlayerAmmo, fire obj -> "+hit.collider.name); firePos = hit.point; XKNpcHealthCtrl healthScript = hit.collider.GetComponent <XKNpcHealthCtrl>(); if (healthScript != null) { healthScript.OnDamageNpc(ammoScript.DamageNpc, PlayerEnum.Null); } BuJiBaoCtrl buJiBaoScript = hit.collider.GetComponent <BuJiBaoCtrl>(); if (buJiBaoScript != null) { buJiBaoScript.RemoveBuJiBao(PlayerEnum.Null); //buJiBaoScript } } ammoScript.StartMoveAmmo(firePos, PlayerEnum.Null); } } }
// public void SetNpcIsDoFire(NpcMark script) // { // //Debug.Log("Unity:"+"SetNpcIsDoFire -> IsFireFeiJiNpc "+script.IsFireFeiJiNpc); // if (!NpcScript.IsAniMove) { // return; // } // // if (SpawnPointScript == null) { // return; // } // // Transform npcPath = SpawnPointScript.NpcPath; // Transform markPar = script.transform.parent; // if (npcPath != markPar) { // return; // } // //Debug.Log("Unity:"+"***********SetNpcIsDoFire -> IsFireFeiJiNpc "+script.IsFireFeiJiNpc); // NpcScript.SetIsDoFireAnimation(script.IsFireFeiJiNpc); // NpcScript.SetFeiJiMarkInfo(script); // } void Update() { if (!XkGameCtrl.IsMoveOnPlayerDeath) { if (!XkGameCtrl.IsActivePlayerOne && !XkGameCtrl.IsActivePlayerTwo) { return; } } if (IsDeathNPC) { return; } if (!IsTeShuFireNpc) { return; } if (TimeTeShuFire.Length < 1) { return; } //if (Network.peerType == NetworkPeerType.Server) { // return; //} if ((JiFenJieMianCtrl.GetInstance() != null && JiFenJieMianCtrl.GetInstance().GetIsShowFinishTask()) || GameOverCtrl.IsShowGameOver) { return; } if (!NpcScript.GetIsDoFireAnimation()) { return; } if (XkGameCtrl.CheckNpcIsMoveToCameraBack(transform)) { return; } if (XkGameCtrl.GetInstance().IsCreatAmmoOnBoss == false) { if (XkPlayerCtrl.GetInstanceFeiJi().m_SpawnNpcManage.GetIsHaveCaiPiaoBoss() == true) { if (NpcScript != null && NpcScript.IsCaiPiaoZhanChe == true) { } else { //有彩票boss产生,不再继续发射子弹. return; } } } GameObject obj = null; Transform tran = null; for (int i = 0; i < TimeTeShuFire.Length; i++) { TimeTeShuFire[i] += Time.deltaTime; if (TimeTeShuFire[i] >= TimeFireAmmo[i]) { TimeTeShuFire[i] = 0f; //fire ammo // Debug.Log("Unity:"+"teShuFireNpc -> i = "+i); if (i < AudioTeShuNpcFire.Length && AudioTeShuNpcFire[i] != null) { if (AudioTeShuNpcFire[i].isPlaying) { AudioTeShuNpcFire[i].Stop(); } AudioTeShuNpcFire[i].Play(); } //if (AmmoLZPrefabTeShu != null && AmmoLZPrefabTeShu[i] != null && AmmoLZObjTeShu[i] == null) { if (AmmoLZPrefabTeShu != null && AmmoLZPrefabTeShu[i] != null) { obj = (GameObject)Instantiate(AmmoLZPrefabTeShu[i], AmmoSpawnTranTeShu[i].position, AmmoSpawnTranTeShu[i].rotation); tran = obj.transform; //AmmoLZObjTeShu[i] = obj; XkGameCtrl.CheckObjDestroyThisTimed(obj); tran.parent = AmmoSpawnTranTeShu[i]; } PlayerAmmoCtrl ammoPlayerScript = AmmoPrefabTeShu[i].GetComponent <PlayerAmmoCtrl>(); if (ammoPlayerScript != null && !XkGameCtrl.GetInstance().IsCartoonShootTest) { continue; } obj = GetNpcAmmoFromList(AmmoSpawnTranTeShu[i], AmmoPrefabTeShu[i]); if (obj == null) { return; } tran = obj.transform; tran.parent = XkGameCtrl.NpcAmmoArray; NpcAmmoCtrl ammoNpcScript = obj.GetComponent <NpcAmmoCtrl>(); if (ammoNpcScript != null) { ammoNpcScript.SetNpcScriptInfo(NpcScript); ammoNpcScript.SetIsAimFeiJiPlayer(IsAimFeiJiPlayer); } 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("Unity:"+"npc fire PlayerAmmo, fire obj -> "+hit.collider.name); firePos = hit.point; XKNpcHealthCtrl healthScript = hit.collider.GetComponent <XKNpcHealthCtrl>(); if (healthScript != null) { healthScript.OnDamageNpc(ammoScript.DamageNpc, PlayerEnum.Null); } BuJiBaoCtrl buJiBaoScript = hit.collider.GetComponent <BuJiBaoCtrl>(); if (buJiBaoScript != null) { buJiBaoScript.RemoveBuJiBao(PlayerEnum.Null); //buJiBaoScript } } ammoScript.StartMoveAmmo(firePos, PlayerEnum.Null, null, AmmoMovePath); } } // if (AmmoLiZiPrefab != null) { // obj = (GameObject)Instantiate(AmmoLiZiPrefab, AmmoSpawnTran.position, AmmoSpawnTran.rotation); // tran = obj.transform; // tran.parent = XkGameCtrl.MissionCleanup; // } } } }
// Update is called once per frame void Update() { if (!IsSpawnAmmo || TimeTeShuFire.Length < 1) { return; } if (CountAmmo >= MaxAmmo) { //停止发射子弹. IsSpawnAmmo = false; return; } GameObject obj = null; Transform tran = null; for (int i = 0; i < TimeTeShuFire.Length; i++) { TimeTeShuFire[i] += Time.deltaTime; if (TimeTeShuFire[i] >= TimeFireAmmo[i]) { TimeTeShuFire[i] = 0f; //fire ammo //Debug.Log("teShuFireNpc -> i = "+i); if (CountAmmo >= MaxAmmo) { return; } if (i < AudioTeShuNpcFire.Length && AudioTeShuNpcFire[i] != null) { if (AudioTeShuNpcFire[i].isPlaying) { AudioTeShuNpcFire[i].Stop(); } AudioTeShuNpcFire[i].Play(); } if (AmmoLZPrefabTeShu != null && AmmoLZPrefabTeShu.Length >= TimeTeShuFire.Length && AmmoLZPrefabTeShu[i] != null && AmmoLZObjTeShu[i] == null) { obj = (GameObject)Instantiate(AmmoLZPrefabTeShu[i], AmmoSpawnTranTeShu[i].position, AmmoSpawnTranTeShu[i].rotation); tran = obj.transform; AmmoLZObjTeShu[i] = obj; XkGameCtrl.CheckObjDestroyThisTimed(obj); tran.parent = AmmoSpawnTranTeShu[i]; } obj = (GameObject)Instantiate(AmmoPrefabTeShu[i], AmmoSpawnTranTeShu[i].position, AmmoSpawnTranTeShu[i].rotation); if (obj == null) { return; } tran = obj.transform; tran.parent = XkGameCtrl.NpcAmmoArray; tran.position = AmmoSpawnTranTeShu[i].position; tran.rotation = AmmoSpawnTranTeShu[i].rotation; NpcAmmoCtrl ammoNpcScript = obj.GetComponent <NpcAmmoCtrl>(); if (ammoNpcScript != null) { ammoNpcScript.SetAmmoTargetObject(null); ammoNpcScript.SetNpcScriptInfo(NpcScript); ammoNpcScript.SetIsAimFeiJiPlayer(false); } CountAmmo++; } } }