Question by
Foxi · Feb 27, 2021 at 08:19 PM ·
scripting problemscripting beginnerparticle systemscore system
Number of particles based on score collected?
Hi, in my 2D game player collect ,,coins" and they count of how many has been collected. I want particles flying around the player, but only the number of how many has been collected. So if player collects 7 coins, then 7 coins will be flying around the player. Is it possible? if so, can you help me with the code? I'm code newbie. I know I need to somehow mention (already created and set) particle system in the script and somehow mention and change the Rate Over Time. But I have absolutely no idea how.
Score counter:
public class ScoreManager : MonoBehaviour
{
public static ScoreManager instance;
public TextMeshProUGUI text;
int score;
// Start is called before the first frame update
void Start()
{
if(instance == null)
{
instance = this;
}
}
public void ChangeScore(int coinValue)
{
score += coinValue;
text.text = score.ToString();
}
}
Comment
Answer by Foxi · Feb 27, 2021 at 08:26 PM
Nevermind. Got it. For anyone in the future(script below). Just assing the particle system in inspector and set Rate over time to 0.
public class ScoreManager : MonoBehaviour
{
public static ScoreManager instance;
public TextMeshProUGUI text;
int score;
public ParticleSystem par;
// Start is called before the first frame update
void Start()
{
if(instance == null)
{
instance = this;
}
}
public void ChangeScore(int coinValue)
{
score += coinValue;
text.text = score.ToString();
var emission = par.emission;
emission.rateOverTime = score;
}
}