/// <summary> /// 伤害同步处理 /// </summary> /// <param name="att"></param> /// <param name="attackTank"></param> public void NetBeAttacked(float att, GameObject attackTank) { //扣除生命值 if (hp <= 0) { return; } hp -= att; hp = hp <= 0 ? 0 : hp; string ammoStr = weapon.GetAmmoStr(); if (playerCtrl.ctrlType == PlayerController.CtrlType.Player) { // 显示子弹 EventCenter.Broadcast(EventID.UpdateBattleText, ammoStr, ((int)hp).ToString()); } //tank被击毁 if (hp <= 0) { Dead(); // 显示击杀提示 if (attackTank) { Fps_Player player = attackTank.GetComponent <Fps_Player>(); if (player != null && player.playerCtrl.ctrlType == PlayerController.CtrlType.Player) { player.StartDrawKill(); } } } }
// 一些状态的同步 public void NetMoveState(PlayerState state, float h, float v, PlayerState s) { if (player == null) { player = GetComponent <Fps_Player>(); } player.playerAnim.NetMoveVec(h, v, s); }
void OnCollisionEnter(Collision pOther) { string tag = pOther.collider.tag; if (tag == Tags.bullet || pOther.gameObject == shoter) { return; } ContactPoint cantact = pOther.contacts[0]; //判断击中材质类型 GameObject impact = BulletRigidPoolMgr.Singleton.GetImpact("ConcreteImpact"); switch (tag) { case Tags.player: case Tags.enemy: case Tags.unitHead: case Tags.unitBody: case Tags.unitLimbs: impact = BulletRigidPoolMgr.Singleton.GetImpact("BloodImpact"); break; } //生成弹孔 GameObject go = Instantiate(impact); go.transform.position = cantact.point; go.transform.localRotation = Quaternion.LookRotation(cantact.normal); go.transform.parent = pOther.collider.transform; Destroy(go, 10f); DisActive(); //unit.ApplyDamage(injury); Fps_Player player = pOther.gameObject.GetComponent <Fps_Player>(); /** * 多个客户端同时执行该方法, * 只有在受击者的用户名与该客户端的用户名相同时才发送伤害信息 * */ if (player != null && player.name == GameMgr._instance.id) { float att = GetApplyInjury(player.tag); // 发送伤害信息 player.SendHit(shoter.name, att); } }
public void SetTarget(GameObject go) { targetGo = go; if (targetGo) { player = targetGo.GetComponent <Fps_Player>();; // 确保刚体不改变旋转 if (targetGo.GetComponent <Rigidbody>()) { targetGo.GetComponent <Rigidbody>().freezeRotation = true; } CameraFollowPoint = player.playerCtrl.CameraFollowPoint; upperBDTran = player.playerCtrl.upperBDTran; bodyTran = upperBDTran.root; paramter = targetGo.GetComponent <Fps_PlayerParamter>(); } }
void Start() { crouching = false; walking = false; runing = false; speed = normalSpeed; jumpSpeed = normalJumpSpeed; standardCamHeight = mainCamera.localPosition.y; crouchingCamHeight = standardCamHeight - crouchDeltaHeight; normalControllerCenter = controller.center; normalControllerHeight = controller.height; hitNormalCenter = hitCollider.center; // CharacterController只有在Move或者是SimpleMove才检测碰撞 // CC不检测物理碰撞,使用新的碰撞器检测碰撞 controller.detectCollisions = false; player = GetComponent <Fps_Player>(); }
void Start() { player = transform.root.GetComponent <Fps_Player>(); player.playerAnim.Reload1Cb += Reload1; player.playerAnim.Reload2Cb += Reload2; ads = GetComponent <AudioSource>(); paramter = player.GetComponent <Fps_PlayerParamter>(); shootWaitTime = 60 / shootSettings.shootRate; aimStartPosZ = transform.localPosition.z; currentMess = shootSettings.maxMess; currentAmmo = shootSettings.maxAmmo; if (player.playerCtrl.ctrlType == PlayerController.CtrlType.Player) { string ammoStr = GetAmmoStr(); // 显示子弹 EventCenter.Broadcast(EventID.UpdateBattleText, ammoStr, ((int)player.hp).ToString()); } }