示例#1
0
        public override void PlayerDied(RpcArgs args)
        {
            Debug.Log("PlayerDied Fired");
            if (!localPlayerAlive)
            {
                return;
            }
            var pID           = args.GetNext <uint>();
            var target        = args.Info.SendingPlayer;
            int currentDeaths = 0;
            var data          = new ScoreData();

            if (NetworkManager.Instance.IsServer)
            {
                for (int i = 0; i < scores.Count; i++)
                {
                    if (scores[i].playerID == pID)
                    {
                        var score = scores[i];
                        Debug.Log($"Deaths Before{score.deaths}");
                        score.deaths++;
                        Debug.Log($"Deaths After{score.deaths}");
                        scores[i] = score;
                        SyncScores();
                        networkObject.SendRpc(RPC_PLAYER_DIED, Receivers.Others, pID);
                        return;
                    }
                }
            }
            else if (GameManager.instance.PlayerData.netID == pID)
            {
                localPlayerAlive = false;
                foreach (var score in scores.Where(s => pID == s.playerID))
                {
                    data = score;
                    break;
                }
                playerDeath?.Invoke(data.playerIndex, data.deaths);

                Debug.Log("LocalPlayer Died");
                if (data.deaths < MaxDeaths)
                {
                    RespawnPlayer();
                }
                else
                {
                    CheckEndState();
                }
            }
            else
            {
                foreach (var score in scores.Where(s => pID == s.playerID))
                {
                    data = score;
                    break;
                }

                playerDeath?.Invoke(data.playerIndex, data.deaths);
            }
        }
示例#2
0
 public ScoreData(ScoreData other)
 {
     playerIndex = other.playerIndex;
     kills       = other.kills;
     deaths      = other.deaths;
     playerID    = other.playerID;
 }