I’m trying to add to an existing script a way to increase health by 10 points, the health pickup is destroyed so thats no problem. Im getting a CS0019 error can anyone help?
public PlayerHealth playerHealth;
public Slider healthSlider;
public float HealthUp = 10;
//PlayerHealth.currenntHealth playerHealth.currentHealth;
void OnTriggerEnter (Collider col)
{
if (col.gameObject.tag == "Player")
{
Destroy(gameObject);
Debug.Log ("pickup working");
}
}
private void Update ()
{
if (playerHealth < 100)
playerHealth = playerHealth + HealthUp;
}
If I understand your question correctly, you may wish to use “Invoke Repeat”
Thus, as you suggest in your question, you would have some sort of test to see if your health is below a certain amount (playerHealth < maxHealth) etc. If so, you would do something like this:
void Start()
{
InvokeRepeating("HealthIncrease", 5.0f, 1.5f);
}
void HealthIncrease()
{
Health = Health + addSomeNewHealth;
}
So, the function “HealthIncrease” would be called. After 5.0 seconds it would begin. Then every 1.5 seconds it would increase your health by the “addSomeNewHealth” amount. Of course, you would use whatever time and increase amounts were appropriate.
Good luck and I’m sorry if this isn’t what you were asking.