- Home /
Question by
JJNCreator · May 18, 2012 at 12:25 AM ·
damagefirebarhealth
Health Bar fire damage
hi guys. i have a health bar script and i want to have a flame particle system to lower the bar. any suggestions?
below is the script:
using UnityEngine;
using System.Collections;
public class PlayerHealth : 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 ,10, 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
Answer by Alismuffin · May 18, 2012 at 01:19 AM
Create a cube and take off the mesh renderer. Place the box around the particle system and set it to isTrigger. Tell a script on the cube to damage your health when you are inside the trigger
Your answer
Follow this Question
Related Questions
How to create/fix fire damage script???? 1 Answer
Fire Damage 2.0 1 Answer
A node in a childnode? 1 Answer
Colliders, Triggers, Damage, and Fire 2 Answers
Object Not Recieving Damage 3 Answers