i wrote a script like when my score reaches certain amount the game should end and it works but the problem is i have particle effect and when score reaches targeted no game stops and it feels like game paused bcuz particle effect didnot end.
how can i do like after all the effects or animation ended then end the game?
I’m just a little hazy on what exactly you’re aiming to achieve here, but I think I have an idea so I’ll go off of that. It seems like you’re having an issue terminating a particle effect, or having an event (in this case Game Over) occur after a particle effect has finished playing.
There are a couple of ways to do this. The first thing you have to make sure of is that the particle effect in question is not set to looping, because that will keep the “IsPlaying” boolean true, even though it’s passed its duration.
The first way to handle firing an event after a particle effect has terminated is to use the actual duration in seconds within a co-routine. The code would look like this.
public int score;
public int maxScore;
public ParticleSystem pFX;
public bool GameOver;
public IEnumerator EffectPlay()
{
pFX.Play();
yield return new WaitForSeconds(pFX.duration);
pFX.Stop();
GameOver();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (score == maxScore)
{
StartCoroutine(EffectPlay());
}
}
void GameOver()
{
}
The other way to handle it is to run a check on pFX.isPlaying. Which will return true if the particle effect is still playing and false if it isn’t.
Now, part of your post makes it seem as though you may just be having trouble terminating the particle effect. In which case, all you need to do is add a line of code to your GameOver() function : “pFX.Stop()”