C# Poison status effect

Hey guys! Long time no see lol anyways lately i’ve been working on a Player stats script that involves Health, Stats, and status effects. But i’ve run into a stump and cant seem to find anything to make it to where while the player “isPoisoned” their “curHealth” depletes… here’s the script
using UnityEngine;
using System.Collections;

public class PlayerAttributes : MonoBehaviour {
public string levelToLoad;

public int maxHealth = 100;
public int curHealth = 100;

public float healthBarLength;

public int agilty = 1;
public int strength = 1;
public int speed = 1;
public int defense = 1;
public int magicStrength = 1;
public int magicDefense = 1;

public bool isPoisoned = false;
public bool isHeadache = false;
public bool isSlow = false;

public bool isHaste = false;
public bool isRegen = false;
public bool isAutoLife = false;

public float poisonTimer;
public float coolDown;


// Use this for initialization
void Start () {
    healthBarLength = Screen.width / 2;
}

// Update is called once per frame
void Update () {
	if (curHealth == 0){
		Application.LoadLevel(levelToLoad);
	}
	if (isPoisoned == true){
		
	}
	if (isHeadache == true){
		
	}
}

void OnGUI (){
	GUI.Box(new Rect(10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
}

}

any ideas as to how to make it work? Im still not the best at scripting :confused:

//add this at the top where your variables are
bool poisonEffect = true ;
public int poisonDamage = 5 ; //set this to whatever in inspector
//also set your “poisonTimer” variable to whatever seconds in inspector
 
//add this to update area
if(isPoisoned){
StartCoroutine(“PoisonDamage”) ;
}
 
//add this new function OUTSIDE of any other functions
IEnumerator PoisonDamage(){
if(poisonEffect){
curHealth -= poisonDamage ;
poisonEffect = false ;
yield return new WaitForSeconds(poisonTimer) ;
poisonEffect = true ;
}
}

and that should do it.

Hi there,
I know I’m way too late for this script but I tried it and it worked perfectly.
However, I have to check the Boolean manually to have the effect occur and it also doesn’t show in the health bar the depletion of the character’s health.
please if you could help me out I’d be really grateful.

here’s my script:

public float maxHealth;
    public GameObject deathFX;
    public AudioClip playerHurt;

    public float currentHealth;
    PlayerController controlMovement;
    AudioSource playerAS;

    public Slider healthBar;
    public Image damageScreen;

    bool damaged = false;
    Color damagedColor = new Color(0f, 0f, 0f, .5f);
    float smoothColor = 5f;

    public bool isPoisoned;
    public bool poisonEffect;
    public int poisonDamage;
    public float poisonTimer;

	// Use this for initialization
	void Start () {
        isPoisoned = false;
        currentHealth = maxHealth;
        controlMovement = GetComponent<PlayerController>();

        healthBar.maxValue = maxHealth;
        healthBar.value = maxHealth;
        damaged = false;

        playerAS = GetComponent<AudioSource>();
	}
	
	// Update is called once per frame
	void Update () {
        if (damaged)
        {
            damageScreen.color = damagedColor;
        }
        else
        {
            damageScreen.color = Color.Lerp(damageScreen.color, Color.clear, smoothColor * Time.deltaTime);
        }
        damaged = false;

        if (isPoisoned)
        {
            StartCoroutine("PoisonDamage");
        }

        if (currentHealth <= 0)
            Die();
	}

    public void TakeDamage(float damage)
    {
        if (damage <= 0)
            return;

        currentHealth -= damage;
        playerAS.clip = playerHurt;
        playerAS.Play();

        isPoisoned = true;

        healthBar.value = currentHealth;
        damaged = true;

        if (currentHealth <= 0)
        {
            Die();
        }
    }

    public void Die()
    {
        Instantiate(deathFX, transform.position, transform.rotation);
        Destroy(gameObject);
    }

    IEnumerator PoisonDamage()
    {
        if (poisonEffect)
        {
            poisonEffect = true;
            currentHealth -= poisonDamage;
            poisonEffect = false;
            yield return new WaitForSeconds(poisonTimer);
            poisonEffect = true;
        }