ArenMook

Boss HP bar

Dec 28th, 2015
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. UISprite fg = NGUITools.Draw<UISprite>("fg", delegate(UISprite sp)
  2. {
  3.     sp.depth = 1;
  4.     sp.atlas = Resources.Load<UIAtlas>("UI/Atlas - Windward");
  5.     sp.spriteName = "Flat";
  6.     sp.type = UISprite.Type.Sliced;
  7.     sp.color = new Color(0.25f, 1f, 0f, 1f);
  8.     sp.pivot = UIWidget.Pivot.TopLeft;
  9.     sp.SetAnchor(0.5f, -200,
  10.         0.8f, -10,
  11.         0.5f, 200,
  12.         0.8f, 10);
  13.  
  14.     UISprite bg = sp.gameObject.AddWidget<UISprite>(0);
  15.     bg.atlas = sp.atlas;
  16.     bg.spriteName = "Flat";
  17.     bg.type = UISprite.Type.Sliced;
  18.     bg.color = new Color(0.2f, 0.2f, 0.2f, 1f);
  19.     bg.pivot = UIWidget.Pivot.TopLeft;
  20.     bg.SetAnchor(0f, 0,
  21.         0f, 0,
  22.         1f, 0,
  23.         1f, 0);
  24.  
  25.     UILabel lbl = sp.gameObject.AddWidget<UILabel>(2);
  26.     lbl.name = "Name";
  27.     lbl.pivot = UIWidget.Pivot.BottomLeft;
  28.     lbl.bitmapFont = Resources.Load<UIFont>("UI/Font - Qlassik22");
  29.     lbl.fontSize = lbl.bitmapFont.defaultSize;
  30.     lbl.effectStyle = UILabel.Effect.Shadow;
  31.     lbl.gradientBottom = new Color(0.5f, 0.5f, 0.5f, 1f);
  32.     lbl.SetAnchor(0f, 5,
  33.         1f, 2,
  34.         0f, sp.width - 10,
  35.         1f, 30);
  36.  
  37.     UISlider slider = sp.gameObject.AddComponent<UISlider>();
  38.     slider.backgroundWidget = bg;
  39.     slider.foregroundWidget = sp;
  40. });
  41.  
  42. RuntimeBehaviour.Create().onUpdate = delegate(RuntimeBehaviour rb)
  43. {
  44.     if (UILoadingScreen.isVisible) return;
  45.     UISlider slider = fg.GetComponent<UISlider>();
  46.  
  47.     for (int i = 0; i < GameShip.list.size; ++i)
  48.     {
  49.         GameShip ship = GameShip.list[i];
  50.  
  51.         if (ship != null && ship.isActive && ship.bossTier == 4 && ship.factionID == 0)
  52.         {
  53.             slider.value = ship.health;
  54.             Transform child = slider.transform.FindChild("Name");
  55.            
  56.             if (child != null)
  57.             {
  58.                 UILabel lbl = child.GetComponent<UILabel>();
  59.                 if (lbl != null) lbl.text = ship.name;
  60.             }
  61.             return;
  62.         }
  63.     }
  64.  
  65.     UnityEngine.Object.Destroy(fg.gameObject);
  66.     rb.onUpdate = null;
  67. };
Advertisement
Add Comment
Please, Sign In to add comment