Пример #1
0
 public List <Playerdata> GetScoreBoard()
 {
     GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
     // Clear so we dont duplicate
     listofPlayers.Clear();
     if (players.Length > 0)
     {
         foreach (GameObject player in players)
         {
             if (player != null)
             {
                 PlayerClientController pc = player.GetComponent <PlayerClientController> ();
                 Playerdata             pd;
                 pd.name   = pc.playerName;
                 pd.kills  = pc.kills;
                 pd.deaths = pc.deaths;
                 listofPlayers.Add(pd);
             }
         }
         return(listofPlayers);
     }
     else
     {
         print("No players in the scene");
         return(listofPlayers);
     }
 }
Пример #2
0
    // Other functions that can be called anywhere
    // You must manually specify what code runs on the client/server
    public void TakeDamage(float amount, PlayerClientController sourcePlayer)
    {
        if (!isServer)
        {
            return;
        }

        RpcPlayHitSound();
        if (playerArmor >= amount)
        {
            playerArmor -= amount;
        }
        else
        {
            if (playerArmor > 0)
            {
                // Get the remainder damage from the armor, and take the damage to our health
                float remainder = amount - playerArmor;
                playerArmor = 0;
                TakeDamage(remainder, sourcePlayer);
            }
            else
            {
                playerHealth -= amount;
                if (playerHealth <= 0)
                {
                    OnPlayerDeath(sourcePlayer);
                }
            }
        }
    }
Пример #3
0
    void OnPlayerDeath(PlayerClientController sourcePlayer)
    {
        if (sourcePlayer != this)
        {
            sourcePlayer.kills++;
            sourcePlayer.RpcShowPlayerKillfeed(playerName);
        }
        if (sourcePlayer.kills >= Scoreboard.killsToWin)
        {
            EndGameData.playerWhoWon = sourcePlayer.playerName;
            RpcSetGameEnd(sourcePlayer.playerName);
        }

        deaths++;

        // Update gun instances on both the client and server
        for (int i = 0; i < hasGun.Count; i++)
        {
            gunInstances[i].GetComponent <BaseWeapon>().resetWeaponForRespawn();
            gunInstances[i].gameObject.SetActive(false);
            hasGun[i]    = false;
            ammoCache[i] = 0;
        }

        gunInstances[0].gameObject.SetActive(true);
        hasGun[0] = true;


        if (isServer)
        {
            playerHealth = maxHealth;
            playerArmor  = 0;
            ammoCache[0] = gunInstances[0].GetComponent <BaseWeapon>().RefillAmmo();
            // TODO: instead of respawning right away, show a death screen/respawn screen
            // called on the Server, but invoked on the Clients
            RpcOnPlayerDeath();
        }
    }
Пример #4
0
 protected virtual void Start()
 {
     bulletSpawn = transform.Find("BulletSpawn");
     //playerCamera  = GetComponentInParent<Camera>();
     owner = transform.parent.GetComponentInParent <PlayerClientController>();
 }
Пример #5
0
 public void SetPlayerOwner(PlayerClientController player)
 {
     owner = player;
 }
Пример #6
0
 public void SetControllerReference(PlayerClientController controller)
 {
     controllerRef = controller;
 }
Пример #7
0
 public void SetOwner(PlayerClientController player)
 {
     this.owner = player;
 }