I have a delay in my code now, but it is not waiting the amounted seconds I had assigned it.
What do I do know?
The Codes I added are on lines 11-13 and 51-55
Do I have to add something in the middle or add something else to the IEnumerator?
Here is the Code:
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public Transform target;
public float healthBarLength;
IEnumerator Do() {
yield return new WaitForSeconds(2);
}
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
animation["death"].wrapMode = WrapMode.Once;
animation["death"].layer = 1;
}
// 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);
if(curHealth <= 0){
animation.Play ("death");
Do();
Application.LoadLevel(2);
}
}
}