I am extremely new to C# and scripting in general. I need help making this do
curHealth = (curHealth - 1)
, or decrease curHealth by 1, every 9 seconds. I have looked into coroutines, but I do not fully understand them.
Here is my script:
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 / 1;
}
void Update () {
AdjustCurrentHealth (0);
}
void OnGUI() {
GUI.Box (new Rect (4, 4, healthBarLength, 8), 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 / 1) * (curHealth / (float)maxHealth);
}
}
Thank you for your time and any help.