Advertisement
AndrewRosyaev

PlayerInfo.cs

Nov 24th, 2015
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.Networking;
  4.  
  5. public class PlayerInfo : NetworkBehaviour
  6. {
  7.     [SyncVar] public int Health = 100;
  8.     public TextMesh tm;
  9.  
  10.     void Start ()
  11.     {
  12.         transform.name = "Player " + GetComponent<NetworkIdentity> ().netId.ToString ();
  13.     }
  14.     void Update()
  15.     {
  16.         tm.text = transform.name + "/Health "+Health;
  17.     }
  18.  
  19.     public void GetDamage(int dmg)
  20.     {
  21.         Health -= dmg;
  22.     }
  23.  
  24.     void OnGUI()
  25.     {
  26.         if (isLocalPlayer)
  27.         {
  28.             GUI.Label(new Rect(Screen.width-100,25,200,50),"Health: "+Health);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement