diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index faab573..bd89bc9 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -2458,6 +2458,7 @@ MonoBehaviour: - {fileID: 6383810576328763588} - {fileID: 8413760021314526160} - {fileID: 3176123164317376148} + growAnimation: {fileID: 902566665} --- !u!4 &1465666065 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/View/Scene/GrowAnimation.cs b/Assets/Scripts/View/Scene/GrowAnimation.cs index c397867..3c71a08 100644 --- a/Assets/Scripts/View/Scene/GrowAnimation.cs +++ b/Assets/Scripts/View/Scene/GrowAnimation.cs @@ -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().Score; _spawnRose = FindObjectOfType().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) diff --git a/Assets/Scripts/View/Scene/GrowParticlesSpawner.cs b/Assets/Scripts/View/Scene/GrowParticlesSpawner.cs index ce77e5c..9d3b608 100644 --- a/Assets/Scripts/View/Scene/GrowParticlesSpawner.cs +++ b/Assets/Scripts/View/Scene/GrowParticlesSpawner.cs @@ -10,6 +10,8 @@ namespace View.Scene { [SerializeField] private GrowParticle growParticle; [SerializeField] private Transform[] growParticlePositions; + [SerializeField] private GrowAnimation growAnimation; + private Score _score; private void Awake() { @@ -22,11 +24,17 @@ namespace View.Scene { public void OnInputReceived() { float randomRotation = Random.Range(0, 360); - growParticle.Spawn(GetGrowParticlePosition(), Quaternion.Euler(0, 0, randomRotation)); + if(growAnimation.Growing) + growParticle.Spawn(GetGrowParticlePosition(), Quaternion.Euler(0, 0, randomRotation)); } private Vector3 GetGrowParticlePosition() { float iterationStep = 1f / _score.SpawnRate; + bool isLastGrowStep = _score.Value % (_score.GrowIterations * _score.SpawnRate) == 0; + + if(isLastGrowStep) + return growParticlePositions[^1].position; + for (int i = 0; i < growParticlePositions.Length; i++) { if (_score.GrowPercentage < (i + 1) * iterationStep) return growParticlePositions[i].position;