- Home /
Enemy Health Help
I have this script which shows the enemy's health, but I'm going to have multiple enemy's so i dont want to the enemys health to show on my screen, can anyone help?
script:
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(0);
}
void OnGUI() {
GUI.Box(new Rect(10, 40, healthBarLength, 20), 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 / 2) * (curHealth / (float)maxHealth);
}
}
Comment
Best Answer
Answer by kevork · Sep 19, 2011 at 05:01 PM
Delete the OnGUI() function, and you won't have any health bars on your screen.
Your answer
Follow this Question
Related Questions
Destroying Enemy Help 5 Answers
Trap Door Question 1 Answer
How to create Enemy Health Bar ? 4 Answers
Death upon health = 0 2 Answers
Healthbar above enemy : 2d 2 Answers