protected override void SendNetMessage() { //枪械颤抖 ,需要停止当前颤抖协程。再重新开启 StopCoroutine("GunRecoilAnimation"); StartCoroutine("GunRecoilAnimation", m_SniperView.m_Weapon); cameraOffsetY = 0; currentFireTime = TimerSvc.Instance.GetNowTime(); //发射子弹的偏移,网络协议加上偏移 if (currentFireTime - lastFireTime < weapenRocoilTime * 1000) { PECommon.Log("后坐力起效果"); cameraOffsetY = Random.Range(1f, weapenRocoil); } lastFireTime = TimerSvc.Instance.GetNowTime(); if (BattleSys.Instance.battleMgr != null) { if (BattleSys.Instance.battleMgr.playerEntity != null) { //人物枪模上升 BattleSys.Instance.battleMgr.playerEntity.SetDir(new Vector2(0, -360 + cameraOffsetY)); } } MyVector3 originPos = UnityTools.GetMyV3Value(m_SniperView.GunPoint.position); MyVector3 endPos = null; if (Hit.point != Vector3.zero) { shootSky = 0; endPos = UnityTools.GetMyV3Value(Hit.point); } else { shootSky = 1; endPos = UnityTools.GetMyV3Value(m_SniperView.GunPoint.position); endPos.z += 100; } GameMsg gameMsg = new GameMsg { cmd = (int)CMD.ReqSyncLaser, reqSyncLaser = new ReqSyncLaser { originPos = originPos, endPos = endPos, shootSky = shootSky, fireEffect = FireEffect, } }; netSvc.SendMsg(gameMsg); PECommon.Log("发送发射激光消息"); }
public override void CollisionEnter(Collision collision) { PECommon.Log("碰到物体的名字是:" + collision.collider.transform.name); M_Rigidbody.Sleep(); TimerSvc.Instance.RemoveTake(taskID); taskID = -10; TimerSvc.Instance.RemoveTake(trailTaskID); trailTaskID = -100; TimerSvc.Instance.AddTimeTask((int tid) => { bulletPool.AddObject(gameObject); }, 500); if (collision.collider.GetComponent <BulletMark>() != null) { if (Physics.Raycast(ray, out hit, 1000, ~(1 << 10))) { } collision.collider.GetComponent <BulletMark>().CreateBulletMark(hit); } GameObject targetPlayer = UnityTools.FindUpParent(collision.collider.transform).gameObject; if (targetPlayer.tag == "Player") { Vector3 hitPos = collision.collider.transform.position; MyVector3 hitPosMyV3 = UnityTools.GetMyV3Value(hitPos); PECommon.Log("射中的目标最上层物体的名字:" + UnityTools.FindUpParent(collision.collider.transform).gameObject.name); //---------------------------------- if (targetPlayer.GetComponent <ControllerBase>() == null) { return; } //别射到自己。 RoleType targetPlayerRoleType = targetPlayer.GetComponent <ControllerBase>().roleType; if (casterRoleType == targetPlayerRoleType) { return; } int hurt = 0; switch (collision.collider.gameObject.tag) { case "Arm": hurt = damage / 2; PECommon.Log("造成肢体伤害" + hurt); break; case "Body": hurt = damage; PECommon.Log("造成身体伤害" + hurt); break; case "Head": hurt = damage * 2; PECommon.Log("造成头部伤害" + hurt); break; } //发送网络消息 GameMsg gameMsg = new GameMsg { cmd = (int)CMD.ReqTakeDamage, reqTakeDamage = new ReqTakeDamage { damageID = damageID, casterRoleType = casterRoleType, targetRoleType = targetPlayerRoleType, hurt = hurt, hitPos = hitPosMyV3, }, }; netSvc.SendMsg(gameMsg); //准星变红 if (casterRoleType == BattleSys.Instance.GetCurrentRoleType()) { BattleSys.Instance.SetSignRed(); } } gameObject.SetActive(false); }
protected override void SendNetMessage() { Vector3 forceDir = Vector3.zero; //枪械颤抖 ,需要停止当前颤抖协程。再重新开启 StopCoroutine("GunRecoilAnimation"); StartCoroutine("GunRecoilAnimation", m_RifleView.m_Weapon); cameraOffsetY = 0; cameraOffsetX = 0; currentFireTime = TimerSvc.Instance.GetNowTime(); //发射子弹的偏移,网络协议加上偏移 if (currentFireTime - lastFireTime < weapenRocoilTime * 1000) { PECommon.Log("后坐力起效果"); cameraOffsetY = Random.Range(1f, weapenRocoil); cameraOffsetX = Random.Range(-weapenRocoil, weapenRocoil) * 0.3f; } lastFireTime = TimerSvc.Instance.GetNowTime(); if (BattleSys.Instance.battleMgr != null) { if (BattleSys.Instance.battleMgr.playerEntity != null) { //人物枪模上升 BattleSys.Instance.battleMgr.playerEntity.SetDir(new Vector2(-360 + cameraOffsetX, -360 + cameraOffsetY)); } } if (Hit.point != Vector3.zero) { forceDir = m_RifleView.GunPoint.forward + (Hit.point - m_RifleView.GunPoint.position); shootSky = 0; } else { //forceDir = new Vector3(m_RifleView.m_Weapon.rotation.x, m_RifleView.m_Weapon.rotation.y, 1); PECommon.Log("向天上射:" + forceDir); forceDir = m_RifleView.GunPoint.forward; shootSky = 1; } MyVector3 originPos = UnityTools.GetMyV3Value(m_RifleView.GunPoint.position); MyVector3 originRot = UnityTools.GetMyV3Value(m_RifleView.GunPoint.eulerAngles); MyVector3 dir = UnityTools.GetMyV3Value(forceDir); GameMsg gameMsg = new GameMsg { cmd = (int)CMD.ReqSyncBullet, reqSyncBullet = new ReqSyncBullet { //prefabName = Constants.BulletPrefab, prefabName = BulletPrefab, fireEffect = FireEffect, shellEffect = ShellEffect, originPos = originPos, originRot = originRot, dir = dir, force = Constants.BulletForce, shootSky = shootSky, } //子弹的预制体,子弹的方向,子弹的力,子弹的初始位置。 }; netSvc.SendMsg(gameMsg); PECommon.Log("发送发射子弹消息"); }