Hey here is the code:
int in editor is equal 10
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class deadlyPlant : MonoBehaviour
{
public int damagetime;
public void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
StartCoroutine(StartTakingDamage());
}
}
IEnumerator StartTakingDamage()
{
while (damagetime > 0)
{
yield return new WaitForSeconds(4f);
damagetime --;
Debug.Log(damagetime);
}
}
}
As far as I remember decrementation decrease variable by 1, but Debug in editor shows that every secound int was decreased by 1 twice. Cen some one tell me why? Maybe there is some thing wrong with loop? Please help me understand why it`s working like that.
Thx,Hey, here is th code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class deadlyPlant : MonoBehaviour
{
public int damagetime;
public void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
StartCoroutine(StartTakingDamage());
}
}
IEnumerator StartTakingDamage()
{
while (damagetime >= 0)
{
yield return new WaitForSeconds(4f);
damagetime --;
Debug.Log(damagetime);
}
}
}
Int = 10 in editor
As far as I know decrementation decrese variable by 1 but Debug every 4 secounds decrease number by 1 twice. Its probably something with my code. I
m beginner so can someone help me understand why it`s working that way?