how to save time and take the next variable in enum?
When the button is pressed, the time goes off (5 minutes), but if another button was pressed (terminating IEnumerator), the time stops and if the button is pressed again, then the time goes on, so also that after 5 minutes "enum" changes to the next
public enum MonthEnum { Undefined, January, February, March, April, May, June, July, August, September, October ,November, December }
public void OnClickStart()
{
StartCoroutine ("Month");
}
public void OnClickEnd()
{
// Remember time of stop
StopCoroutine("Month");
}
IEnumerator Month()
{
while (true)
{
// i dont know how to change enum to next
yield return new WaitForSeconds(300.0f); // and i dont know how to remember the time of OnClickEnd and continue OnClickStart
}
}
Comment
Answer by kalen_08 · Jul 21, 2018 at 03:43 PM
This works for me!
public enum MonthEnum {January, February, March}
MonthEnum currentMonth = MonthEnum.January;
void Update ()
{
NextMonth();
print(currentMonth.ToString());
}
// prints: January, February, March, January, February ect.....
void NextMonth ()
{
var length = System.Enum.GetNames(typeof(MonthEnum)).Length;
currentMonth = (MonthEnum)(
((int)currentMonth + 1) % length
);
}
Let me know if it works for you!
Your answer
Follow this Question
Related Questions
C# missingReferenceException when comparing enums 0 Answers
I Keep Getting Error CS0052 1 Answer
C# Mouselook Script errors, need assistance. 1 Answer
Why am I getting this error with my BannerAD (Admob) 1 Answer
AddRigidBody Script Error 1 Answer