WACK-A-MOLE QUEST: ‘Stop The Party’ - Solutions

Quest: Wack-A-Mole Quest
Challenge: Stop The Party

Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.

Alright, feeling much better about knocking these out. Looks like we already had a Bool for use in Scorer.cs

    void Update()
    {
        if (transform.childCount == 0 && hasChildren)
        {
            celebration.Play();
            hasChildren = false;
        }
    }
4 Likes

You could also do this:

        if (transform.childCount == 0)
        {
            celebration.Play();
            Destroy(gameObject, celebration.main.duration);
        }
3 Likes

Came up with the same solution.

Here’s another solution:

void Update()
    {
        if (transform.childCount == 0)
        {
            StartCoroutine(playCelebration(1));
        }
    }

    IEnumerator playCelebration(int seconds)
    {
        celebration.Play();
        yield return new WaitForSeconds(1);
        celebration.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);

    }
}
2 Likes

I solved this task with a timer

public class Scorer : MonoBehaviour
{
    private float startTimer;
    [SerializeField] private float timerWaitFor = 2f;

    [SerializeField] ParticleSystem celebration;
    bool hasChildren = true;

    void Update()
    {
        if (transform.childCount == 0)
        {
            celebration.Play();
            startTimer += Time.deltaTime;
            hasChildren = false;
        }

        if (!hasChildren && startTimer >= timerWaitFor)
        {
            celebration.Stop();
            startTimer = timerWaitFor;
        }
    }
}

I came up with a pretty simple solution, I think…

public class Scorer : MonoBehaviour
{
    [SerializeField] ParticleSystem celebration;
    bool hasChildren = true;
    bool hasPlayed;

    void Update()
    {
        if (hasPlayed == false)
        {
            if (transform.childCount == 0)
            {
                celebration.Play();
                hasPlayed = true;
            }
        }
    }
}

Nice! Not sure if you know this but you can do (!hasPlayed) instead of (hasPlayed == false). It took me forever to realize this so just pointing it out. :slight_smile:

1 Like

Had to add a couple lines since the bool variable already existed to be used.

public class Scorer : MonoBehaviour
{
    [SerializeField] ParticleSystem celebration;
    bool hasChildren = true;

    void Update()
    {
        if (transform.childCount == 0 && hasChildren)
        {
            celebration.Play();
            hasChildren = !hasChildren;
        }
    }
}

Privacy & Terms