void OnCollisionEnter(Collision colInfo)
{
if (colInfo.collider.tag == “Infection”)
{
Debug.Log(“IF STATEMENT”);
health = health - 1;
Die();
}
}
void OnCollisionStay(Collision stayInfo)
{
while (stayInfo.collider.tag == "Infection")
{
timer = 0;
timer += Time.deltaTime;
if(timer == 1)
{
health -= 1;
timer = 0;
}
Die();
Debug.Log("WHILE STATEMENT");
}
}
void Die()
{
if (health <= 0)
{
Destroy(gameObject);
Instantiate(infection, transform.position, transform.rotation);
}
}
Not exactly sure why it’s having issues… I read to be careful with while statements and this really doesn’t seem like it’s running infinitely. It runs fine with the if statement in OnCollisionEnter but doesn’t work with the while statement in OnCollisionStay.