Advertisement
Munchy2007

PlayerHealth_Full

Jan 10th, 2018
4,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace PUNTutorial
  6. {
  7.     public class PlayerHealth : Photon.PunBehaviour
  8.     {
  9.         const int MAX_HP = 100;
  10.         int hitPoints = MAX_HP;
  11.  
  12.         public void DoDamage(Missile missile)
  13.         {
  14.             hitPoints = Mathf.Clamp(hitPoints - missile.damage, 0 , MAX_HP);
  15.             Debug.Log(GetHealthString());
  16.         }
  17.  
  18.         string GetHealthString()
  19.         {
  20.             return new System.Text.StringBuilder()
  21.                 .Append("Health = ")
  22.                 .Append(hitPoints / (float)MAX_HP * 100)
  23.                 .Append("%")
  24.                 .ToString();
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement