Advertisement
Munchy2007

Unet5TutPt4TeamManager

Feb 21st, 2016
4,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.Networking;
  4.  
  5. public class TeamManager : NetworkBehaviour {
  6.     public static TeamManager instance;
  7.     static int playerCount;
  8.  
  9.     void Awake()
  10.     {
  11.         if(instance == null)
  12.         {
  13.             instance = this;
  14.             DontDestroyOnLoad(gameObject);
  15.         }
  16.         else
  17.         {
  18.             DestroyImmediate(gameObject);
  19.             return;
  20.         }
  21.     }
  22.  
  23.     [Server]
  24.     public static void SetPlayerTeam(GameObject newPlayer)
  25.     {
  26.         var player = newPlayer.GetComponent<NetworkPlayer>();
  27.         player.teamNumber = (int)Mathf.Repeat(playerCount, 2);
  28.         playerCount++;
  29.     }
  30.  
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement