Your function requires a return value of an IEnumerator in order to yield correctly. Unfortunately, OnTriggerEnter is called expecting a void return value.
void OnTriggerEnter(Collider other)
{
if (other.tag == "Hazard")
{
curHealth -= 20;
StartCoroutine(Flasher); //VERY IMPORTANT! You 'must' start coroutines with this code.
}
}
// Functions to be used as Coroutines MUST return an IEnumerator
IEnumerator Flasher()
{
for (int i = 0; i < 5; i++)
{
renderer.material.color = collideColor;
yield return new WaitForSeconds(.1f);
renderer.material.color = normalColor;
yield return new WaitForSeconds(.1f);
}
}
The last loop just makes it “flash”, instead of only changing color once.