void Awake() { _Instance = this; PlayerAmmoCtrl ammoScript = AmmoChangCheng.GetComponent <PlayerAmmoCtrl>(); ammoScript.AmmoIndex = AmmoChangChengIndex; ammoScript.AmmoType = AmmoChangChengType; ammoScript = AmmoQiangJi.GetComponent <PlayerAmmoCtrl>(); ammoScript.AmmoIndex = AmmoQiangJiIndex; ammoScript.AmmoType = AmmoQiangJiType; ammoScript = AmmoPaiJiPao.GetComponent <PlayerAmmoCtrl>(); ammoScript.AmmoIndex = AmmoPaiJiPaoIndex; ammoScript.AmmoType = AmmoPaiJiPaoType; ammoScript = AmmoSanDanZP.GetComponent <PlayerAmmoCtrl>(); ammoScript.AmmoIndex = AmmoSanDanZPIndex; ammoScript.AmmoType = AmmoSanDanZPType; ammoScript = AmmoChuanJiaDanZP.GetComponent <PlayerAmmoCtrl>(); ammoScript.AmmoIndex = AmmoChuanJiaDanZPIndex; ammoScript.AmmoType = AmmoChuanJiaDanZPType; ammoScript = AmmoHuoLiOpenZP.GetComponent <PlayerAmmoCtrl>(); ammoScript.AmmoIndex = AmmoHuoLiOpenZPIndex; ammoScript.AmmoType = AmmoHuoLiOpenZPType; ammoScript = AmmoHuoLiOpenJQ.GetComponent <PlayerAmmoCtrl>(); ammoScript.AmmoIndex = AmmoHuoLiOpenJQIndex; ammoScript.AmmoType = AmmoHuoLiOpenJQType; }
void AddAmmoToList(PlayerAmmoCtrl scriptAmmo) { if (m_AmmoList.Contains(scriptAmmo)) { return; } m_AmmoList.Add(scriptAmmo); }
void SpawnJiQiangAmmo(int indexVal) { Vector3 ammoSpawnForward = AmmoStartPosOne[indexVal].forward; Vector3 ammoSpawnPos = AmmoStartPosOne[indexVal].position; Quaternion ammoSpawnRot = AmmoStartPosOne[indexVal].rotation; GameObject obj = null; CheckFireAudioPlayerJiQiang(); obj = SpawnPlayerAmmoByAmmoType(JI_QIANG_INDEX, ammoSpawnPos, ammoSpawnRot); if (obj == null) { return; } obj.transform.parent = XkGameCtrl.PlayerAmmoArray; PlayerAmmoCtrl ammoScript = obj.GetComponent<PlayerAmmoCtrl>(); Vector3 mousePosInput = Input.mousePosition; //if (pcvr.bIsHardWare) { //mousePosInput = pcvr.CrossPositionOne; //} RaycastHit hit; Vector3 firePos = Vector3.zero; Vector3 mousePos = mousePosInput + Vector3.forward * OffsetForward; Vector3 posTmp = Camera.main.ScreenToWorldPoint(mousePos); Vector3 ammoForward = Vector3.Normalize( posTmp - ammoSpawnPos ); if (!IsPSAutoFire) { firePos = FirePosValTmp * ammoSpawnForward + ammoSpawnPos; FireRayDirLen = ammoScript.MvSpeed * ammoScript.LiveTime; if (Physics.Raycast(ammoSpawnPos, ammoSpawnForward, out hit, FireRayDirLen, FireLayer.value)) { //Debug.Log("Unity:"+"Player fire obj -> "+hit.collider.name); if (ammoScript.AmmoType != PlayerAmmoType.ChuanTouAmmo) { firePos = hit.point; } } } else { ammoForward = obj.transform.forward; firePos = FirePosValTmp * ammoForward + ammoSpawnPos; if (Physics.Raycast(ammoSpawnPos, ammoForward, out hit, FireRayDirLen, FireLayer.value)) { //Debug.Log("Unity:"+"Player fire obj -> "+hit.collider.name); if (ammoScript.AmmoType != PlayerAmmoType.ChuanTouAmmo) { firePos = hit.point; } } } ammoScript.StartMoveAmmo(firePos, PlayerIndex); }
public void SpawnPlayerDaoDan(Transform ammoTran, GameObject playerDaoDan) { //Debug.Log("Unity:"+"SpawnPlayerDaoDan***"); Vector3 ammoSpawnPos = ammoTran.position; GameObject obj = SpawnPlayerAmmo(playerDaoDan, ammoSpawnPos, ammoTran.rotation); obj.transform.parent = XkGameCtrl.PlayerAmmoArray; PlayerAmmoCtrl ammoScript = obj.GetComponent<PlayerAmmoCtrl>(); RaycastHit hitInfo; float disVal = Random.Range(300f, 500f); Vector3 forwardVal = ammoTran.forward; Vector3 firePos = ammoSpawnPos + (forwardVal * disVal); Physics.Raycast(ammoSpawnPos, forwardVal, out hitInfo, disVal, FireLayer.value); if (hitInfo.collider != null){ firePos = hitInfo.point; } ammoScript.StartMoveAmmo(firePos, PlayerEnum.Null); }
void HandleAmmoList(PlayerAmmoCtrl scriptAmmo) { PlayerAmmoType ammoType = scriptAmmo.AmmoType; switch (ammoType) { case PlayerAmmoType.PuTongAmmo: if (PlayerStEnum == PlayerTypeEnum.FeiJi) { if (AmmoList.Contains(scriptAmmo)) { return; } AmmoList.Add(scriptAmmo); } else if (PlayerStEnum == PlayerTypeEnum.TanKe) { if (AmmoList_TK.Contains(scriptAmmo)) { return; } AmmoList_TK.Add(scriptAmmo); } break; case PlayerAmmoType.GaoBaoAmmo: if (PlayerStEnum == PlayerTypeEnum.FeiJi) { if (AmmoGaoBaoList.Contains(scriptAmmo)) { return; } AmmoGaoBaoList.Add(scriptAmmo); } else if (PlayerStEnum == PlayerTypeEnum.TanKe) { if (AmmoGaoBaoList_TK.Contains(scriptAmmo)) { return; } AmmoGaoBaoList_TK.Add(scriptAmmo); } break; } }
/** * ammoIndex == 0 -> 普通机枪散弹. * ammoIndex == 1 -> 主炮散弹. */ void SpawnPlayerSanDanAmmo(Transform AmmoStartTran, int ammoIndex = 0) { if (AmmoStartTran == null) { return; } Vector3 ammoSpawnForward = AmmoStartTran.forward; Vector3 ammoSpawnPos = AmmoStartTran.position; Quaternion ammoSpawnRot = AmmoStartTran.rotation; GameObject obj = GetPlayerAmmo(PlayerAmmoType.SanDanAmmo, ammoSpawnPos, ammoSpawnRot, ammoIndex); obj.transform.parent = XkGameCtrl.PlayerAmmoArray; PlayerAmmoCtrl ammoScript = obj.GetComponent<PlayerAmmoCtrl>(); RaycastHit hit; Vector3 firePos = Vector3.zero; firePos = FirePosValTmp * ammoSpawnForward + ammoSpawnPos; if (Physics.Raycast(ammoSpawnPos, ammoSpawnForward, out hit, FireRayDirLen, FireLayer.value)) { //Debug.Log("Unity:"+"Player fire obj -> "+hit.collider.name); firePos = hit.point; } ammoScript.StartMoveAmmo(firePos, PlayerIndex); }
void OtherPortSpawnPlayerAmmo(PlayerAmmoType ammoType, Vector3 ammoSpawnPos, Quaternion ammoSpawnRot, Vector3 firePos) { //GameObject obj = SpawnPlayerAmmo(ammoPlayer, ammoSpawnPos, ammoSpawnRot); GameObject obj = null; switch (ammoType) { case PlayerAmmoType.PuTongAmmo: case PlayerAmmoType.GaoBaoAmmo: obj = GetPlayerAmmo(ammoType, ammoSpawnPos, ammoSpawnRot); break; default: obj = SpawnPlayerAmmo(DaoDanAmmo, ammoSpawnPos, ammoSpawnRot); break; } obj.transform.parent = XkGameCtrl.PlayerAmmoArray; PlayerAmmoCtrl ammoScript = obj.GetComponent <PlayerAmmoCtrl>(); ammoScript.SetIsDonotHurtNpc(true); ammoScript.StartMoveAmmo(firePos, PlayerEnum.Null); }
void SpawnJiQiangAmmo(int indexVal, XKPlayerAutoFire autoFireCom) { if (m_WeaponData.AmmoCreatPoints == null) { return; } Vector3 ammoSpawnForward = m_WeaponData.AmmoCreatPoints[indexVal].forward; Vector3 ammoSpawnPos = m_WeaponData.AmmoCreatPoints[indexVal].position; Quaternion ammoSpawnRot = m_WeaponData.AmmoCreatPoints[indexVal].rotation; GameObject obj = GetFeiJiAmmo(ammoSpawnPos, ammoSpawnRot); if (obj == null) { return; } PlayerAmmoCtrl ammoScript = obj.GetComponent <PlayerAmmoCtrl>(); //float OffsetForward = 30f; float firePosValTmp = 100f; float fireRayDirLen = 100f; //Vector3 mousePosInput = Input.mousePosition; RaycastHit hit; Vector3 firePos = Vector3.zero; //Vector3 mousePos = mousePosInput + Vector3.forward * OffsetForward; //Vector3 posTmp = Camera.main.ScreenToWorldPoint(mousePos); //Vector3 ammoForward = Vector3.Normalize(posTmp - ammoSpawnPos); firePos = firePosValTmp * ammoSpawnForward + ammoSpawnPos; fireRayDirLen = ammoScript.MvSpeed * ammoScript.LiveTime; if (Physics.Raycast(ammoSpawnPos, ammoSpawnForward, out hit, fireRayDirLen, m_FireLayer.value)) { if (ammoScript.AmmoType != PlayerAmmoType.ChuanTouAmmo) { firePos = hit.point; } } ammoScript.StartMoveAmmo(firePos, m_PlayerIndex, autoFireCom); }
void CheckPlayerZhuPaoFireBt() { if (!ScreenDanHeiCtrl.IsStartGame) { return; } // if (!XkGameCtrl.IsActivePlayerTwo) { // return; // } if (XkGameCtrl.GetInstance().m_GamePlayerAiData.IsActiveAiPlayer == true) { //激活主角Ai坦克状态. if (XkGameCtrl.GetInstance().m_AiPathGroup.m_CameraMoveType == AiPathGroupCtrl.MoveState.YuLe) { if (Random.Range(0, 100) % 3 != 0) { return; } } else { if (Random.Range(0, 100) % 30 != 0) { return; } } } else { if (!IsActiveFireBtZP) { return; } if (!CheckIsActivePlayer()) { return; } } // if (DaoJiShiCtrl.GetInstance().GetIsPlayDaoJishi()) { // return; // } if (Camera.main == null) { return; } if (GameOverCtrl.IsShowGameOver || JiFenJieMianCtrl.GetInstance().GetIsShowFinishTask()) { if (GameOverCtrl.IsShowGameOver) { IsActiveFireBtZP = false; } return; } bool isSpawnAmmo = CheckIsSpawnPlayerAmmo(ZHU_PAO_INDEX); if (!isSpawnAmmo) { return; } LastFireTimeZhuPao = Time.time; CheckPlayerHouZuoLi(ZhuPaoAmmoSt, ZHU_PAO_INDEX); Vector3 ammoSpawnForward = AmmoStartPosZP[0].forward; Vector3 ammoSpawnPos = AmmoStartPosZP[0].position; Quaternion ammoSpawnRot = AmmoStartPosZP[0].rotation; GameObject obj = null; CheckFireAudioPlayerZhuPao(); //pcvr.OpenZuoYiQiNang(PlayerIndex); //pcvr.GetInstance().ActiveFangXiangDouDong(PlayerIndex, false); obj = SpawnPlayerAmmoByAmmoType(ZHU_PAO_INDEX, ammoSpawnPos, ammoSpawnRot); if (obj == null) { return; } obj.transform.parent = XkGameCtrl.PlayerAmmoArray; PlayerAmmoCtrl ammoScript = obj.GetComponent<PlayerAmmoCtrl>(); Vector3 mousePosInput = Input.mousePosition; //if (pcvr.bIsHardWare) { //mousePosInput = pcvr.CrossPositionTwo; //} Vector3 firePos = Vector3.zero; Vector3 mousePos = mousePosInput + Vector3.forward * OffsetForward; Vector3 posTmp = Camera.main.ScreenToWorldPoint(mousePos); Vector3 ammoForward = Vector3.Normalize( posTmp - ammoSpawnPos ); RaycastHit hit; if (!IsPSAutoFire) { firePos = FirePosValTmp * ammoSpawnForward + ammoSpawnPos; FireRayDirLen = ammoScript.MvSpeed * ammoScript.LiveTime; if (Physics.Raycast(ammoSpawnPos, ammoSpawnForward, out hit, FireRayDirLen, FireLayer.value)) { //Debug.Log("Unity:"+"Player fire obj -> "+hit.collider.name); if (ammoScript.AmmoType != PlayerAmmoType.ChuanTouAmmo) { firePos = hit.point; } } } else { ammoForward = obj.transform.forward; firePos = FirePosValTmp * ammoForward + ammoSpawnPos; if (Physics.Raycast(ammoSpawnPos, ammoForward, out hit, FireRayDirLen, FireLayer.value)) { //Debug.Log("Unity:"+"Player fire obj -> "+hit.collider.name); if (ammoScript.AmmoType != PlayerAmmoType.ChuanTouAmmo) { firePos = hit.point; } } } ammoScript.StartMoveAmmo(firePos, PlayerIndex); }
void CheckPlayerTwoFireBt() { if (XKPlayerCamera.IndexPlayerNum != 1) { SetQianGuanTwRot(PlayerEnum.PlayerTwo, false); return; } if (!ScreenDanHeiCtrl.IsStartGame) { SetQianGuanTwRot(PlayerEnum.PlayerTwo, false); return; } if (!XkGameCtrl.IsActivePlayerTwo) { SetQianGuanTwRot(PlayerEnum.PlayerTwo, false); return; } if (!IsActiveFireBtTwo) { SetQianGuanTwRot(PlayerEnum.PlayerTwo, false); return; } SetQianGuanTwRot(PlayerEnum.PlayerTwo, true); // if (DaoJiShiCtrl.GetInstance().GetIsPlayDaoJishi()) { // return; // } if (!XkGameCtrl.IsTiaoGuoStartCartoon) { if (!ZhunXingCtrl.GetInstanceTwo().GetActiveZhunXing() || !ZhunXingTeXiaoCtrl.IsOverTeXiaoZhunXing) { return; } } if (Camera.main == null) { return; } // if (GameOverCtrl.IsShowGameOver || JiFenJieMianCtrl.GetInstance().GetIsShowFinishTask()) { // IsActiveFireBtTwo = false; // return; // } // if (PlayerStEnum == PlayerTypeEnum.FeiJi && XkGameCtrl.GameJiTaiSt != GameJiTaiType.FeiJiJiTai) { // IsActiveFireBtTwo = false; // return; // } // if (PlayerStEnum == PlayerTypeEnum.TanKe && XkGameCtrl.GameJiTaiSt != GameJiTaiType.TanKeJiTai) { // IsActiveFireBtTwo = false; // return; // } if (XkGameCtrl.GaoBaoDanNumPTwo <= 0 && Time.time < LastFireTimeTwo + 1f / Frequency) { return; } if (XkGameCtrl.GaoBaoDanNumPTwo > 0 && Time.time < LastFireTimeTwo + 1f / FrequencyGaoBao) { return; } LastFireTimeTwo = Time.time; Vector3 ammoSpawnPos = AmmoStartPosTwo[0].position; GameObject obj = null; CheckFireAudioPlayerTwo(); bool isSpawnGaoBaoDan = false; if (XkGameCtrl.GaoBaoDanNumPTwo <= 0) { if (AmmoParticle[0] != null) { obj = SpawnParticleCom.SpawnParticleObject(AmmoParticle[0], ammoSpawnPos, AmmoStartPosTwo[0].rotation); obj.transform.parent = AmmoStartPosTwo[0]; } obj = GetPlayerAmmo(PlayerAmmoType.PuTongAmmo, ammoSpawnPos, AmmoStartPosTwo[0].rotation); } else { isSpawnGaoBaoDan = true; if (GaoBaoAmmoParticle[0] != null) { obj = SpawnParticleCom.SpawnParticleObject(GaoBaoAmmoParticle[0], ammoSpawnPos, AmmoStartPosTwo[0].rotation); obj.transform.parent = AmmoStartPosTwo[0]; } XkGameCtrl.GetInstance().SubGaoBaoDanNumPTwo(); obj = GetPlayerAmmo(PlayerAmmoType.GaoBaoAmmo, ammoSpawnPos, AmmoStartPosTwo[0].rotation); } obj.transform.parent = XkGameCtrl.PlayerAmmoArray; PlayerAmmoCtrl ammoScript = obj.GetComponent <PlayerAmmoCtrl>(); ammoScript.SetIsDonotHurtNpc(false); Vector3 mousePosInput = pcvr.GetPlayerMousePos(PlayerEnum.PlayerTwo); Vector3 firePos = Vector3.zero; Vector3 mousePos = mousePosInput + Vector3.forward * OffsetForward; Vector3 posTmp = Camera.main.ScreenToWorldPoint(mousePos); Vector3 ammoForward = Vector3.Normalize(posTmp - ammoSpawnPos); Ray ray = Camera.main.ScreenPointToRay(mousePosInput); RaycastHit hit; if (!IsPSAutoFire) { //firePos = FirePosValTmp * ammoForward + ammoSpawnPos; if (Physics.Raycast(ray, out hit, FireRayDirLen, FireLayer.value)) { //Debug.Log("Player fire obj -> "+hit.collider.name); //firePos = hit.point; if (ammoScript.AmmoType == PlayerAmmoType.PuTongAmmo) { XKNpcHealthCtrl healthScript = hit.collider.GetComponent <XKNpcHealthCtrl>(); if (healthScript != null && !healthScript.GetIsDeathNpc()) { healthScript.OnDamageNpc(ammoScript.AmmoType, PlayerEnum.PlayerTwo); } } BuJiBaoCtrl buJiBaoScript = hit.collider.GetComponent <BuJiBaoCtrl>(); if (buJiBaoScript != null) { buJiBaoScript.RemoveBuJiBao(PlayerEnum.PlayerTwo); //buJiBaoScript } } firePos = GunLaser[1].PlayerCursorTr.position; } else { ammoForward = obj.transform.forward; firePos = FirePosValTmp * ammoForward + ammoSpawnPos; if (Physics.Raycast(ammoSpawnPos, ammoForward, out hit, FireRayDirLen, FireLayer.value)) { //Debug.Log("Player fire obj -> "+hit.collider.name); firePos = hit.point; if (ammoScript.AmmoType == PlayerAmmoType.PuTongAmmo) { XKNpcHealthCtrl healthScript = hit.collider.GetComponent <XKNpcHealthCtrl>(); if (healthScript != null && !healthScript.GetIsDeathNpc()) { healthScript.OnDamageNpc(ammoScript.AmmoType, PlayerEnum.PlayerTwo); } } BuJiBaoCtrl buJiBaoScript = hit.collider.GetComponent <BuJiBaoCtrl>(); if (buJiBaoScript != null) { buJiBaoScript.RemoveBuJiBao(PlayerEnum.PlayerTwo); //buJiBaoScript } } } if (hit.collider == null) { ammoScript.StartMoveAmmo(firePos, PlayerEnum.PlayerTwo); } else { ammoScript.StartMoveAmmo(firePos, PlayerEnum.PlayerTwo, null, hit.collider.gameObject); } if (isSpawnGaoBaoDan) { //Call OtherPort Show AmmoParticle PlayerScript.CallOtherPortSpawnPlayerAmmoParticle(2, 2, firePos); } else { //Call OtherPort Show AmmoParticle PlayerScript.CallOtherPortSpawnPlayerAmmoParticle(2, 0, firePos); } }
IEnumerator PlayPaoGuanAnimation() { CountPaoGuanAni++; if (CountPaoGuanAni > 1) { //Debug.LogWarning("Unity:"+"PlayPaoGuanAnimation -> CountPaoGuanAni "+CountPaoGuanAni); yield break; } int count = 0; int maxCount = 1; float speed = PaoGuanZhenFu / maxCount; bool isBackPaoGuan = false; bool isFireAmmo = false; IsPlayPaoGuanAnimation = true; do { if (IsDeathNpc || GameOverCtrl.IsShowGameOver) { yield break; } if (IsStopAnimation || !IsDoFireAnimation || Time.realtimeSinceStartup - TimeStartSpawn < TimeFireDelay || JiFenJieMianCtrl.GetInstance().GetIsShowFinishTask()) { yield return(new WaitForSeconds(0.1f)); 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.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("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, AmmoMovePath); } } if (!XkGameCtrl.IsNoFireLiZi) { obj = (GameObject)Instantiate(DaPaoAmmoLiZi, SpawnAmmoPoint[0].position, SpawnAmmoPoint[0].rotation); tran = obj.transform; XkGameCtrl.CheckObjDestroyThisTimed(obj); tran.parent = SpawnAmmoPoint[0]; } } } else { PaoGuan.position += PaoGuan.forward * speed; count--; if (count <= 0) { IsPlayPaoGuanAnimation = false; isBackPaoGuan = false; isFireAmmo = false; count = 0; yield return(new WaitForSeconds(TimeDanGuanFire)); IsPlayPaoGuanAnimation = true; continue; } } yield return(new WaitForSeconds(PaoGuanShenSuoSD)); } while (true); }
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); } } }
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 (DaPaoAmmoLiZi != null) { obj = SpawnParticleCom.SpawnParticleObject(DaPaoAmmoLiZi, SpawnAmmoPoint[0].position, SpawnAmmoPoint[0].rotation); tran = obj.transform; } 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); }
GameObject GetPlayerAmmo(PlayerAmmoType ammoType, Vector3 ammoPos, Quaternion ammoRot, int ammoIndex = 0) { int max = 0; GameObject objAmmo = null; GameObject ammoPrefab = PuTongAmmo; PlayerAmmoCtrl ammoScript = null; PlayerAmmoCtrl ammoPrefabScript = null; bool isFindAmmo = false; //Debug.Log("Unity:"+"ammoType "+ammoType+", ammoIndex "+ammoIndex+", GetPlayerAmmo"); switch (ammoType) { case PlayerAmmoType.PuTongAmmo: max = AmmoList_TK.Count; for (int i = 0; i < max; i++) { if (!AmmoList_TK[i].gameObject.activeSelf) { ammoPrefabScript = PuTongAmmo.GetComponent<PlayerAmmoCtrl>(); if (IsChangChengFire) { ammoPrefabScript = ChangChengAmmo.GetComponent<PlayerAmmoCtrl>(); } if (IsQiangJiFire) { ammoPrefabScript = QiangJiAmmo.GetComponent<PlayerAmmoCtrl>(); } if (IsHuoLiAllOpen) { ammoPrefabScript = AmmoHuoLiOpenJQ.GetComponent<PlayerAmmoCtrl>(); } ammoScript = AmmoList_TK[i].gameObject.GetComponent<PlayerAmmoCtrl>(); if (ammoPrefabScript.AmmoIndex == ammoScript.AmmoIndex) { objAmmo = AmmoList_TK[i].gameObject; isFindAmmo = true; break; } } } if (!isFindAmmo) { objAmmo = null; } if (objAmmo == null) { if (IsChangChengFire) { ammoPrefab = ChangChengAmmo; } if (IsQiangJiFire) { ammoPrefab = QiangJiAmmo; } if (IsHuoLiAllOpen) { ammoPrefab = AmmoHuoLiOpenJQ; } objAmmo = SpawnPlayerAmmo(ammoPrefab, ammoPos, ammoRot); HandleAmmoList( objAmmo.GetComponent<PlayerAmmoCtrl>() ); } break; case PlayerAmmoType.DaoDanAmmo: max = AmmoDaoDanList_TK.Count; for (int i = 0; i < max; i++) { if (!AmmoDaoDanList_TK[i].gameObject.activeSelf) { ammoPrefabScript = DaoDanZPAmmo.GetComponent<PlayerAmmoCtrl>(); if (IsHuoLiAllOpen) { ammoPrefabScript = AmmoHuoLiOpenZP.GetComponent<PlayerAmmoCtrl>(); } ammoScript = AmmoDaoDanList_TK[i].gameObject.GetComponent<PlayerAmmoCtrl>(); if (ammoPrefabScript.AmmoIndex == ammoScript.AmmoIndex) { objAmmo = AmmoDaoDanList_TK[i].gameObject; isFindAmmo = true; break; } } } if (!isFindAmmo) { objAmmo = null; } if (objAmmo == null) { ammoPrefab = DaoDanZPAmmo; if (IsHuoLiAllOpen) { ammoPrefab = AmmoHuoLiOpenZP; } objAmmo = SpawnPlayerAmmo(ammoPrefab, ammoPos, ammoRot); HandleAmmoList( objAmmo.GetComponent<PlayerAmmoCtrl>() ); } break; /*case PlayerAmmoType.GaoBaoAmmo: max = AmmoGaoBaoList_TK.Count; for (int i = 0; i < max; i++) { if (!AmmoGaoBaoList_TK[i].gameObject.activeSelf) { objAmmo = AmmoGaoBaoList_TK[i].gameObject; break; } } if (objAmmo == null) { objAmmo = SpawnPlayerAmmo(GaoBaoDanAmmo, ammoPos, ammoRot); HandleAmmoList( objAmmo.GetComponent<PlayerAmmoCtrl>() ); } break;*/ case PlayerAmmoType.SanDanAmmo: max = AmmoSanDanList_TK.Count; for (int i = 0; i < max; i++) { if (!AmmoSanDanList_TK[i].gameObject.activeSelf) { if (ammoIndex == 1) { ammoPrefabScript = AmmoSanDanZP.GetComponent<PlayerAmmoCtrl>(); } ammoScript = AmmoSanDanList_TK[i].gameObject.GetComponent<PlayerAmmoCtrl>(); if (ammoPrefabScript.AmmoIndex == ammoScript.AmmoIndex) { objAmmo = AmmoSanDanList_TK[i].gameObject; isFindAmmo = true; break; } } } if (!isFindAmmo) { objAmmo = null; } if (objAmmo == null) { if (ammoIndex == 1) { objAmmo = SpawnPlayerAmmo(AmmoSanDanZP, ammoPos, ammoRot); } HandleAmmoList( objAmmo.GetComponent<PlayerAmmoCtrl>() ); } break; /*case PlayerAmmoType.GenZongAmmo: max = AmmoGenZongDanList_TK.Count; for (int i = 0; i < max; i++) { if (!AmmoGenZongDanList_TK[i].gameObject.activeSelf) { objAmmo = AmmoGenZongDanList_TK[i].gameObject; break; } } if (objAmmo == null) { objAmmo = SpawnPlayerAmmo(GenZongDanAmmo, ammoPos, ammoRot); HandleAmmoList( objAmmo.GetComponent<PlayerAmmoCtrl>() ); } break;*/ case PlayerAmmoType.PaiJiPaoAmmo: max = AmmoPaiJiPaoList_TK.Count; for (int i = 0; i < max; i++) { if (!AmmoPaiJiPaoList_TK[i].gameObject.activeSelf) { objAmmo = AmmoPaiJiPaoList_TK[i].gameObject; break; } } if (objAmmo == null) { objAmmo = SpawnPlayerAmmo(PaiJiPaoAmmo, ammoPos, ammoRot); HandleAmmoList( objAmmo.GetComponent<PlayerAmmoCtrl>() ); } break; case PlayerAmmoType.ChuanTouAmmo: max = AmmoChuanTouDanList_TK.Count; for (int i = 0; i < max; i++) { if (!AmmoChuanTouDanList_TK[i].gameObject.activeSelf) { objAmmo = AmmoChuanTouDanList_TK[i].gameObject; break; } } if (objAmmo == null) { objAmmo = SpawnPlayerAmmo(ChuanTouDanAmmo, ammoPos, ammoRot); HandleAmmoList( objAmmo.GetComponent<PlayerAmmoCtrl>() ); } break; /*case PlayerAmmoType.JianSuAmmo: max = AmmoJianSuDanList_TK.Count; for (int i = 0; i < max; i++) { if (!AmmoJianSuDanList_TK[i].gameObject.activeSelf) { objAmmo = AmmoJianSuDanList_TK[i].gameObject; break; } } if (objAmmo == null) { objAmmo = SpawnPlayerAmmo(JianSuDanAmmo, ammoPos, ammoRot); HandleAmmoList( objAmmo.GetComponent<PlayerAmmoCtrl>() ); } break;*/ } if (objAmmo != null) { objAmmo.transform.position = ammoPos; objAmmo.transform.rotation = ammoRot; } return objAmmo; }
void ClickDaoDanBtOneEvent(ButtonState state) { if (XKPlayerCamera.IndexPlayerNum != 0) { return; } if (XKTriggerClosePlayerUI.IsClosePlayerUI) { return; } if (!gameObject.activeSelf) { return; } if (!ScreenDanHeiCtrl.IsStartGame) { return; } if (!XkGameCtrl.IsActivePlayerOne) { return; } if (state != ButtonState.DOWN) { return; } if (XkGameCtrl.GetInstance().GetDaoDanNumPOne() <= 0) { XKGlobalData.GetInstance().PlayDaoDanJingGaoAudio(); return; } // if (PlayerStEnum == PlayerTypeEnum.FeiJi && XkGameCtrl.GameJiTaiSt != GameJiTaiType.FeiJiJiTai) { // return; // } // // if (PlayerStEnum == PlayerTypeEnum.TanKe && XkGameCtrl.GameJiTaiSt != GameJiTaiType.TanKeJiTai) { // return; // } if (Camera.main == null) { return; } // if (!ZhunXingCtrl.GetInstanceOne().GetActiveZhunXing() || !ZhunXingTeXiaoCtrl.IsOverTeXiaoZhunXing) { // return; // } if (Time.realtimeSinceStartup - DaoDanTimeVal[0] < DaoDanTimeMin) { XKGlobalData.GetInstance().PlayDaoDanJingGaoAudio(); return; } DaoDanTimeVal[0] = Time.realtimeSinceStartup; Vector3 ammoSpawnPos = DaoDanAmmoPosOne[0].position; GameObject obj = null; if (DaoDanAmmoParticle[0] != null) { obj = SpawnParticleCom.SpawnParticleObject(DaoDanAmmoParticle[0], ammoSpawnPos, DaoDanAmmoPosOne[0].rotation); obj.transform.parent = XkGameCtrl.PlayerAmmoArray; } if (PlayerAudio[2].isPlaying) { PlayerAudio[2].Stop(); } PlayerAudio[2].Play(); obj = SpawnPlayerAmmo(DaoDanAmmo, ammoSpawnPos, DaoDanAmmoPosOne[0].rotation); obj.transform.parent = XkGameCtrl.PlayerAmmoArray; PlayerAmmoCtrl ammoScript = obj.GetComponent <PlayerAmmoCtrl>(); XkGameCtrl.GetInstance().SubDaoDanNumPOne(); Vector3 mousePosInput = pcvr.GetPlayerMousePos(PlayerEnum.PlayerOne); Vector3 firePos = Vector3.zero; Vector3 mousePos = mousePosInput + Vector3.forward * OffsetForward; Vector3 posTmp = Camera.main.ScreenToWorldPoint(mousePos); Vector3 ammoForward = Vector3.Normalize(posTmp - ammoSpawnPos); firePos = FirePosValTmp * ammoForward + ammoSpawnPos; Ray ray = Camera.main.ScreenPointToRay(mousePosInput); RaycastHit hit; if (!IsPSAutoFire) { firePos = FirePosValTmp * ammoForward + ammoSpawnPos; if (Physics.Raycast(ray, out hit, FireRayDirLen, FireLayer.value)) { //Debug.Log("Player fire obj -> "+hit.collider.name); firePos = hit.point; BuJiBaoCtrl buJiBaoScript = hit.collider.GetComponent <BuJiBaoCtrl>(); if (buJiBaoScript != null) { buJiBaoScript.RemoveBuJiBao(PlayerEnum.PlayerOne); //buJiBaoScript } } } else { ammoForward = obj.transform.forward; firePos = FirePosValTmp * ammoForward + ammoSpawnPos; if (Physics.Raycast(ammoSpawnPos, ammoForward, out hit, FireRayDirLen, FireLayer.value)) { //Debug.Log("Player fire obj -> "+hit.collider.name); firePos = hit.point; BuJiBaoCtrl buJiBaoScript = hit.collider.GetComponent <BuJiBaoCtrl>(); if (buJiBaoScript != null) { buJiBaoScript.RemoveBuJiBao(PlayerEnum.PlayerOne); //buJiBaoScript } } } ammoScript.StartMoveAmmo(firePos, PlayerEnum.PlayerOne); //Call OtherPort Show DaoDanAmmoParticle PlayerScript.CallOtherPortSpawnPlayerAmmoParticle(1, 1, firePos); }
// Use this for initialization void Awake() { _Instance = this; CheckPlayerAmmoFrequency(); for (int i = 0; i < 2; i++) { if (AmmoParticle[i] == null) { Debug.LogWarning("Unity:" + "AmmoParticle[" + i + "] is null"); AmmoParticle[i].name = "null"; return; } } for (int i = 0; i < 2; i++) { if (SanDanAmmoParticle[i] == null) { Debug.LogWarning("Unity:" + "SanDanAmmoParticle[" + i + "] is null"); SanDanAmmoParticle[i].name = "null"; return; } } for (int i = 0; i < 2; i++) { if (PaiJiPaoAmmoParticle[i] == null) { Debug.LogWarning("Unity:" + "PaiJiPaoAmmoParticle[" + i + "] is null"); PaiJiPaoAmmoParticle[i].name = "null"; return; } } for (int i = 0; i < 2; i++) { if (ChuanTouDanAmmoParticle[i] == null) { Debug.LogWarning("Unity:" + "ChuanTouDanAmmoParticle[" + i + "] is null"); ChuanTouDanAmmoParticle[i].name = "null"; return; } } for (int i = 0; i < 2; i++) { if (DaoDanAmmoParticle[i] == null) { Debug.LogWarning("Unity:" + "DaoDanAmmoParticle[" + i + "] is null"); DaoDanAmmoParticle[i].name = "null"; return; } } if (DeathExplodPrefab == null) { Debug.LogWarning("Unity:" + "DeathExplodPrefab is null"); DeathExplodPrefab.name = "null"; return; } if (PlayerMoveList != null) { PlayerMoveList.Clear(); } PlayerAmmoCtrl ammoScript = PuTongJQAmmo.GetComponent <PlayerAmmoCtrl>(); ammoScript.AmmoIndex = AmmoPuTongJQIndex; ammoScript.AmmoType = AmmoPuTongJQType; ammoScript = DaoDanZPAmmo.GetComponent <PlayerAmmoCtrl>(); ammoScript.AmmoIndex = AmmoDaoDanZPIndex; ammoScript.AmmoType = AmmoDaoDanZPType; }
// 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; // } } } }
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 HandleAmmoList(PlayerAmmoCtrl scriptAmmo) { PlayerAmmoType ammoType = scriptAmmo.AmmoType; switch (ammoType) { case PlayerAmmoType.PuTongAmmo: if (AmmoList_TK.Contains(scriptAmmo)) { return; } AmmoList_TK.Add(scriptAmmo); break; case PlayerAmmoType.DaoDanAmmo: if (AmmoDaoDanList_TK.Contains(scriptAmmo)) { return; } AmmoDaoDanList_TK.Add(scriptAmmo); break; case PlayerAmmoType.GaoBaoAmmo: if (AmmoGaoBaoList_TK.Contains(scriptAmmo)) { return; } AmmoGaoBaoList_TK.Add(scriptAmmo); break; case PlayerAmmoType.SanDanAmmo: if (AmmoSanDanList_TK.Contains(scriptAmmo)) { return; } AmmoSanDanList_TK.Add(scriptAmmo); break; case PlayerAmmoType.GenZongAmmo: if (AmmoGenZongDanList_TK.Contains(scriptAmmo)) { return; } AmmoGenZongDanList_TK.Add(scriptAmmo); break; case PlayerAmmoType.PaiJiPaoAmmo: if (AmmoPaiJiPaoList_TK.Contains(scriptAmmo)) { return; } AmmoPaiJiPaoList_TK.Add(scriptAmmo); break; case PlayerAmmoType.ChuanTouAmmo: if (AmmoChuanTouDanList_TK.Contains(scriptAmmo)) { return; } AmmoChuanTouDanList_TK.Add(scriptAmmo); break; case PlayerAmmoType.JianSuAmmo: if (AmmoJianSuDanList_TK.Contains(scriptAmmo)) { return; } AmmoJianSuDanList_TK.Add(scriptAmmo); break; } }