(adsbygoogle = window.adsbygoogle || []).push({});
Im trying to subtract 1 from my health after a specific amount of time and having trouble implementing this. im trying to use Time.deltaTime but im SUPER novice at C# and cant really get it.
can you help me out and explain why it works? thanks!
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour
{
public int maxHealth = 100;
public int curHealth = 100;
public float subtractHealth = -1f;
public float healthBarLength;
// Use this for initialization
void Start()
{
healthBarLength = Screen.width / 3;
}
// Update is called once per frame
void Update()
{
AdjustCurrentHealth (0);
}
void OnGUI()
{
GUI.Box(new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
}
public void AdjustCurrentHealth(int adj)
{
curHealth += adj;
if (curHealth < 0)
curHealth = 0;
if (curHealth > maxHealth)
curHealth = maxHealth;
if (maxHealth < 1)
maxHealth = 1;
healthBarLength = (Screen.width / 3) * (curHealth / (float)maxHealth);
}
}