fix: grow animation spawning at correct positions

This commit is contained in:
Gerard Gascón 2024-04-22 11:49:01 +02:00
parent a06779c5c1
commit f0af2a5a07
3 changed files with 19 additions and 5 deletions

View file

@ -19,6 +19,8 @@ namespace View.Scene {
private SpawnRose _spawnRose;
private bool _firstUpdate = true;
public bool Growing { private set; get; } = true;
private void Start() {
_score = FindObjectOfType<Dependencies>().Score;
_spawnRose = FindObjectOfType<Dependencies>().Spawner;
@ -35,6 +37,7 @@ namespace View.Scene {
}
if (animationName == "Rosa_End") {
Growing = true;
_spawnRose.Execute();
animator.ChangeAnimation(growAnimation);
animator.PlayUntil(_score.GrowPercentage);
@ -43,17 +46,19 @@ namespace View.Scene {
public void GrowStep() {
if (animator.CurrentAnimation == "Rosa_Grow") {
animator.PlayUntil(IsLastGrowState(_score.Value, _score.GrowPercentage) ? 1f : _score.GrowPercentage);
if (IsLastGrowState())
Growing = false;
animator.PlayUntil(IsLastGrowState() ? 1f : _score.GrowPercentage);
if (_score.GrowPercentage < 1f && !_firstUpdate)
RuntimeManager.PlayOneShot(growEvent);
}
_firstUpdate = false;
}
private bool IsLastGrowState(int score, float growPercentage) {
if (growPercentage != 0)
public bool IsLastGrowState() {
if (_score.GrowPercentage != 0)
return false;
bool isLastFrame = score % (_score.GrowIterations * _score.SpawnRate) == 0;
bool isLastFrame = _score.Value % (_score.GrowIterations * _score.SpawnRate) == 0;
if (!isLastFrame)
return false;
if (_firstUpdate)