Я использую переменную полного цикла, вращение начинает замедляться и остановиться после 6 полных петель. Я хотел бы реализовать это таким образом, чтобы левый конец останавливался после 6 циклов, средний после 7, правый после 8. Просто вообще не могу этого понять. Если бы кто-нибудь мог мне помочь, я был бы очень признателен.
Код: Выделить всё
private IEnumerator SpinReels()
{
isSpinning = true;
float distanceCovered = 0f;
// Calculate the total distance to spin for the specified number of loops
float totalDistance = fullLoops * reelSymbols[0].Length * symbolHeight;
// Spin until the distance covered reaches total distance
while (distanceCovered < totalDistance)
{
foreach (var reel in reelSymbols)
{
foreach (GameObject symbolObj in reel)
{
RectTransform symbol = symbolObj.GetComponent();
// Move the symbol upwards based on current spin speed and delta time
symbol.anchoredPosition += new Vector2(0, spinSpeed * Time.deltaTime);
// Wrap symbols back to the bottom once they move beyond the top
if (symbol.anchoredPosition.y > (reel.Length * symbolHeight) / 2f)
{
symbol.anchoredPosition -= new Vector2(0, reel.Length * symbolHeight);
}
}
}
// Calculate distance covered
distanceCovered += spinSpeed * Time.deltaTime;
yield return null; // Wait for the next frame
}
// Gradually slow down after completing full loops
while (spinSpeed > 0)
{
foreach (var reel in reelSymbols)
{
foreach (GameObject symbolObj in reel)
{
RectTransform symbol = symbolObj.GetComponent();
// Move the symbol upwards based on current spin speed and delta time
symbol.anchoredPosition += new Vector2(0, spinSpeed * Time.deltaTime);
// Wrap symbols back to the bottom once they move beyond the top
if (symbol.anchoredPosition.y > (reel.Length * symbolHeight) / 2f)
{
symbol.anchoredPosition -= new Vector2(0, reel.Length * symbolHeight);
}
}
}
// Gradually decrease speed
spinSpeed -= slowdownRate * Time.deltaTime;
yield return null; // Wait for the next frame
}
// Ensure we stop completely
spinSpeed = 0;
isSpinning = false;
Ch
Подробнее здесь: https://stackoverflow.com/questions/790 ... er-another