Question by
BloodyBow · Sep 16, 2015 at 03:25 PM ·
scripting problemscript.scriptingbasics
Can some one help me with my C# script? (HUD)
hello, i make a little survival game, and i make a hud system, but i can’t finish it, because i don’t know how, ia have to add the food system and stamina to my hud, if you can help me i will be very happy.
This is The HUD
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class HUD : MonoBehaviour {
//Health
public Image health;
public float HealthPercentage;
//Hunger
public Image hunger;
public float HungerPercentage;
//Thirst
public Image thirst;
public float ThirstPercentage;
//Stamina
void Start()
{
HungerPercentage = 0.9f;
ThirstPercentage = 0.9f;
HealthPercentage = 1f;
}
// Update is called once per frame
void Update ()
{
//Hunger
HungerPercentage -= 0.002f * Time.deltaTime;
HungerPercentage = Mathf.Clamp (HungerPercentage, 0, 1);
hunger.fillAmount = HungerPercentage;
//Thirst
ThirstPercentage -= 0.0025f * Time.deltaTime;
ThirstPercentage = Mathf.Clamp (ThirstPercentage, 0, 1);
thirst.fillAmount = ThirstPercentage;
//Stamina
//Health
if ((HungerPercentage <= 0) && (ThirstPercentage <= 0)) {
HealthPercentage -= 0.0025f * Time.deltaTime;
health.fillAmount = HealthPercentage;
} else {
if ((HungerPercentage <= 0) || (ThirstPercentage <= 0)) {
HealthPercentage -= 0.0025f * Time.deltaTime;
health.fillAmount = HealthPercentage;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Set public gameobject by raycast hit target 1 Answer
How do i make an uppercut attack? 0 Answers
change game character/controller when inside box - RFPSP 1 Answer
Outside the zone 0 Answers
Need help to reduce my script 0 Answers