- Home /
This question was
closed Apr 10, 2013 at 11:48 PM by
Loius for the following reason:
Duplicate Question: Please read the FAQ before posting a question.
Question by
$$anonymous$$ · Sep 12, 2012 at 09:51 PM ·
health barhealth
Can someone write me a health script? 2
soryy the first one didnt work. Can someone write me a health script to go with this haelth bar i made?
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour
{
public int maxHealth = 100;
public int curHealth = 100;
public float healthBarLength;
void Start ()
{
healthBarLength = Screen.width / 6;
}
void Update ()
{
AddjustCurrentHealth(0);
}
void OnGUI ()
{
GUI.backgroundColor = Color.red;
GUI.Button(new Rect(145, 35, healthBarLength, 24), curHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj)
{
curHealth += adj;
if(curHealth < 0)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
healthBarLength = (Screen.width / 6) * (curHealth / (float)maxHealth);
}
}
Help would be greatly appreciated. Thanks
Comment
Answer by Riessu · Apr 10, 2013 at 10:46 PM
No answer ?! nobody can help this men ?!
And don't write that you wrote this script if you know and I know its made by burgZergArcade