- Home /
This question was
closed Jun 19, 2012 at 01:32 AM by
Wolfram for the following reason:
Was resolved without explaining how (or what the problem was)
This post has been wikified, any user with enough reputation can edit it.
Question by
BloodyRayne89 · Jun 17, 2012 at 06:00 AM ·
c#burgzergarcade
Burgzergarcade tutorial
Hello uhm i am doing the Burgzergarcades tutorial for over like 2 weeks now and i want to change some of the specs for my vital script to be changed to height not the width cause my GUI.Texture is a circle.Its from the Burgzergarcade free assets.Heres my script:
using UnityEngine; using System.Collections;
public class VitalBar : MonoBehaviour {
public bool _isPlayerHealthBar; //This boolean value tells us if this is the playerHealthBar or the mob healthbar
private int _maxBarHeight; //This is how large the vital bar can be if the target is at 100% health.
private int _curBarHeight; //This is the current height of the vital bar.
private GUITexture _display;
// Use this for initialization
void Start () {
// _isPlayerHealthBar = true;
_display = gameObject.GetComponent<GUITexture>();
_maxBarHeight = (int)_display.pixelInset.width;
OnEnable();
}
// Update is called once per frame
void Update () {
}
//This method is called when the GameObject is enabled.
public void OnEnable() {
if(_isPlayerHealthBar)
Messenger<int, int>.AddListener("player health update", OnChangeHealthBarSize);
else
Messenger<int, int>.AddListener("mob health update", OnChangeHealthBarSize);
}
//This method is called when the GameObject is disabled.
public void OnDisable() {
if(_isPlayerHealthBar)
Messenger<int, int>.RemoveListener("player health update", OnChangeHealthBarSize);
else
Messenger<int, int>.RemoveListener("mob health update", OnChangeHealthBarSize);
}
//This method will calculate the total size of the health bar in relation to the % to the health the target has left
public void OnChangeHealthBarSize(int curHealth, int maxHealth) {
// Debug.Log("We heard an event: curHeal = " + curHealth + " - maxHealth = " + maxHealth);
_curBarHeight = (int)((curHealth / (float)maxHealth) * _maxBarHeight); //This calculates the current bar length base on the players health %.
_display.pixelInset = new Rect(_display.pixelInset.x, _display.pixelInset.yMin, _curBarHeight, _display.pixelInset.height);
}
//Setting the healthBar to the player or mob
public void SetPlayerHealthBar(bool b) {
_isPlayerHealthBar = b;
}
}
Comment
Besides being a script dump, you did not even ask a question.
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
How do I load customized characters into my next scene? 2 Answers
C# how to have a part of an object rotate while animation is being played 2 Answers
Set the position of GUIBox 1 Answer