- Home /
Question by
Gearmouse · Jun 08, 2018 at 01:31 AM ·
if-statementstypecondition
if statement condition with calculation inside problem
I am quite new to c# and unity.
I have a if else statement which confuses me.
public float onTime;
public float offTime;
public float flashIndex = 0;
public float repeatTime = 0.1f;
IEnumerator ObjcBlinking()
{
yield return new WaitForSeconds(repeatTime);
float time = onTime + offTime;
if (flashIndex <= onTime)
{
rend.enabled = true;
}
else if (flashIndex <= (onTime + offTime))
{
rend.enabled = false;
}
else
{
flashIndex = 0;
}
flashIndex += repeatTime;
StartCoroutine(ObjcBlinking());
}
The else if (flashIndex <= (onTime + offTime))
doesn't work correctly. But if I changed it into else if (flashIndex <= (float)(onTime + offTime))
it works fine.
Just wonder why I need a type transform for this case to make it work properly?
Comment
Your answer

Follow this Question
Related Questions
Use a #if statement to check if a script exists in project? 0 Answers
Display message when max height is reached 1 Answer
Question on Possible FOR Loop Condition Conflict 0 Answers
conditional spawning 1 Answer
Multiple conditions being called???? 0 Answers