Advertisement
Crazist

Untitled

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