There is a certain method for initiating the start of the cortina:
public void Initialize(float variable){ var newestcorutine = StartCoroutine(MyCorutine(variable)); } And there can be a lot of such instances. The goal is to compare variable values (for example, to find a large) slice of all the currently operating instances.
How can this be done if it can be done (it seems to me that it is possible, but I can’t even imagine where to start to compare the variable with myself)?
Korutina itself has an approximate appearance of the type:
private IEnumerator MyCorutine(float variable1, int variable2) { var durationTimerS = Stopwatch.StartNew(); var durationTimerA = Stopwatch.StartNew(); while (durationTimerS.Elapsed.TotalSeconds <= variable1) { var timeLeft = variable1 - durationTimerS.Elapsed.TotalSeconds; BindedText.text = timeLeft.ToString("0"); if (variableBool == false) { durationTimerS.Stop(); durationTimerS.Reset(); durationTimerA.Stop(); durationTimerA.Reset(); yield break; } if (durationTimerS.Elapsed.TotalSeconds >= (duration / 3) * 2 && durationTimerA.Elapsed.TotalSeconds >= 0.4f) { BindedImage().alpha = 0.3f; } if (durationTimerS.Elapsed.TotalSeconds >= (duration / 3) * 2 && durationTimerA.Elapsed.TotalSeconds >= 0.8f) { BindedImage().alpha = 1f; durationTimerA.Reset(); durationTimerA.Start(); } SomeOtherScript.SomeOtherMethod(-variable2, variableBool); yield return null; } variableBool = false; BindedImage().alpha = 0; durationTimerS.Stop(); durationTimerS.Reset(); durationTimerA.Stop(); durationTimerA.Reset(); } The actual task at a certain point in time is to find all the active instances of this cortina and find the variable with the highest value.
At the moment I am solving this problem so there is a global variable of the form public Corutine newCorutine1 and a global variable to it public int variableValue1
I initialize this way so newCorutine1 = StartCorutine (MyCorutine (variable)); and assign variableValue1 = variable;
Respectively, the second instance is launched as newCorutine2 = StartCorutine (MyCorutine (variable)); and assign variableValue2 = variable;
In the cororutine body itself, upon the completion of the instance, I nullify the variableValue. Then later when I need to find the instance with the highest \ smallest value, I simply iterate through the variableValue list. Therefore, I would like to find a less “head on” solution.
MyCorutineon forever or did something and calm down? - Alexey ShimanskyMyCorutinefor example. And that is, there is some kind of solution, but I’m not sure yet whether it will work ..... Although the task itself is somewhat strange. I think it looks like a problem XY - Alexey ShimanskyСоответственно потом когда мне нужно найти инстанс с наибольшим\наименьшим значением я просто делаю перебор по списку variableValue..... something similar and can be done ... declare a dictionary, a key-value. where the key is the identifier of the coroutine, the value is - variable .... and you run exactly according to the dictionary - Alexey Shimansky