38 lines
No EOL
989 B
C#
38 lines
No EOL
989 B
C#
using System;
|
|
using Domain;
|
|
using Pooling;
|
|
using Presenter;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
namespace View.Scene {
|
|
public class GrowParticlesSpawner : MonoBehaviour, IInputCallback {
|
|
[SerializeField] private GrowParticle growParticle;
|
|
[SerializeField] private Transform[] growParticlePositions;
|
|
|
|
private Score _score;
|
|
|
|
private void Awake() {
|
|
growParticle.CreatePool();
|
|
}
|
|
|
|
private void Start() {
|
|
_score = FindObjectOfType<Dependencies>().Score;
|
|
}
|
|
|
|
public void OnInputReceived() {
|
|
float randomRotation = Random.Range(0, 360);
|
|
growParticle.Spawn(GetGrowParticlePosition(), Quaternion.Euler(0, 0, randomRotation));
|
|
}
|
|
|
|
private Vector3 GetGrowParticlePosition() {
|
|
float iterationStep = 1f / _score.SpawnRate;
|
|
for (int i = 0; i < growParticlePositions.Length; i++) {
|
|
if (_score.GrowPercentage < (i + 1) * iterationStep)
|
|
return growParticlePositions[i].position;
|
|
}
|
|
|
|
return growParticlePositions[^1].position;
|
|
}
|
|
}
|
|
} |