Advertisement
Crazist

Untitled

Mar 23rd, 2023
750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1.  private IEnumerator WaitUntillDisableAllCoins()
  2.         {
  3.             _coroutineInPlay = true;
  4.              
  5.             float minDistance = Mathf.Infinity;
  6.             Vector3 closestPosition = Vector3.zero;
  7.             IWork _stray = null;
  8.             Coin _coin = null;
  9.             bool waitWhileCoinsDisable = false;
  10.             bool inMove = false;
  11.  
  12.             do
  13.             {
  14.                 yield return new WaitForEndOfFrame();
  15.                 waitWhileCoinsDisable = false;
  16.                foreach (var stray in StrayList)
  17.                 {
  18.                     Coin coin = _pool.GetClosestEngagedElementsSecondTouch(stray.getTransform().position);
  19.  
  20.                     if (coin == null)
  21.                     {
  22.                         break;
  23.                     }
  24.                    
  25.                     float distance = Vector3.Distance(stray.getTransform().position, coin.GetTransform().position);
  26.  
  27.                     if (stray.GetAiComponent().GeNavMeshAgent().remainingDistance > 0)
  28.                     {
  29.                         inMove = false;
  30.                     }
  31.  
  32.                     if (distance < minDistance)
  33.                     {
  34.                         _coin = coin;
  35.                         minDistance = distance;
  36.                         closestPosition = stray.getTransform().position;
  37.                         _stray = stray;
  38.                     }
  39.                 }
  40.                 if (_stray != null && Vector3.Distance(_stray.getTransform().position, _coin.GetTransform().position) < _minDistance)
  41.                 {
  42.                     waitWhileCoinsDisable = true;
  43.                     _stray.Move(_coin.transform.position, () => { _coin.Hide(); });
  44.                     _stray = null;
  45.                 }
  46.             } while (waitWhileCoinsDisable || inMove);
  47.  
  48.             _coroutineInPlay = false;
  49.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement