- Home /
Question by
umut323456 · Mar 09, 2019 at 12:30 PM ·
c#if-statementstime.deltatimeupdate function
How to start coroutine for one time in update function when number passed another number
I have a number that will increase and decrease. I want to start a coroutine in update function for only one time when number passes 10 or number decreases from 10. also there will be other milestones like 50 100 500.
I couldn't figure out how can I do that in c#
Comment
Answer by Defetysta · Mar 09, 2019 at 02:17 PM
I think this should do
private float ourValue;
private const float desiredValue = 10f;
private void Start()
{
StartCoroutine(HasValueBeenReached());
}
private IEnumerator HasValueBeenReached()
{
yield return new WaitUntil(() => ourValue >= desiredValue);
}
Your answer
Follow this Question
Related Questions
Update within an if statement not working? 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Input.GetKey(KeyCode.E) requires multiple presses. 1 Answer
If statement behaves unexpectedly 3 Answers