void Start()
    {
        var players = new List <Player> {
            new Player(playerName: "Taro", maxHp: 4),
            new Player(playerName: "Jiro", maxHp: 3),
            new Player(playerName: "Saburo", maxHp: 2)
        };

        List <PlayerBehaviour> playerBehaviours = new List <PlayerBehaviour>();

        foreach (var player in players)
        {
            PlayerBehaviour playerBehaviour = Instantiate(playerBehaviourPrefab);
            playerBehaviour.SetData(player);
            playerBehaviour.OnDead.AddListener(p =>
            {
                Debug.LogFormat("{0} : {1}", p.PlayerName, player.PlayerName);
            });
            playerBehaviours.Add(playerBehaviour);
        }

        foreach (var playerBehaviour in playerBehaviours)
        {
            playerBehaviour.AddDamage(10);
        }
    }
示例#2
0
    public void PlayerHit(PlayerBehaviour _damageDealer, float _damage)
    {
        if (health <= 0)
        {
            //Player allready dead
            Debug.LogWarning("Player allready death, should not be reached");
            return;
        }

        if (!playersDoneDamage.Contains(_damageDealer) && _damageDealer != pb)
        {
            playersDoneDamage.Add(_damageDealer);
        }

        lastPlayerTakenDamageFrom = _damageDealer;
        _damageDealer.AddDamage((int)_damage);

        health -= _damage;
        UpdatePlayerHealthBar(health);

        healthBarFade.StartFade(0.9f);

        pb.Ping(40, 0.2f);

        if (health <= 0)
        {
            healthBarFade.StopFade();

            if (pb.photonView.IsMine)
            {
                photonView.RPC(nameof(RPC_PlayerDied), RpcTarget.AllBuffered);
                photonView.RPC(nameof(RPC_CreateKillFeed), RpcTarget.All, _damageDealer.PlayerName, pb.PlayerName);
                pb.PlayerDie();
            }

            playersDoneDamage.Clear();
        }
    }