Home>

When I cleared the game, I created a script so that confetti would appear, but confetti did not appear. I would appreciate it if you could tell me what the problem is.

In the Clear method, I want to have confetti occur when the game is cleared, but it doesn't work. Debug.Log ("Clear !!") is displayed.

Corresponding source code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using TMPro;
public class UIManager: MonoBehaviour
{
    private TextMeshProUGUI levelText;
    int index;
    public GameObject Top;
    public GameObject Middle;
    public GameObject Bottom;
    public GameObject ConfettiTop;
    public GameObject ConfettiBottom;
    GameObject TopHigh;
    GameObject TopLow;
    GameObject Middle High;
    GameObject MiddleLow;
    GameObject BottomHigh;
    GameObject BottomLow;
    // public delegate void SetCurrentState (GameState state);// Type
    // public SetCurrentState setCurrentState;// Function types that can be registered externally
    // Start is called before the first frame update
    void Start ()
    {
        index = SceneManager.GetActiveScene (). buildIndex;
        index ++;
        changeLevel ();
    }
    // Update is called once per frame
    void Update ()
    {
    }
    public void changeLevel ()
    {
        // Initialize each scene using index (I want to use it in the Level notation of UiManager)
        Debug.Log ("changeLevel ()" + index);
        levelText = this.GetComponent<TextMeshProUGUI>();
        Debug.Log (levelText);
        levelText.text = "Level" + index;
    }
    public void Clear ()
    {
        if (index == 1)
        {
            if (Top.transform.localPosition.y == 0 || Middle.transform.localPosition.y == 102)
            {
                Confetti ();
                Debug.Log ("Clear !!");
            }
        }
        else if (index == 2)
        {

            if (index == 3)
            {
            }
        }
        else if (index == 3)
        {
            TopHigh = GameObject.Find ("TopHigh");
            TopLow = GameObject.Find ("TopLow");
            MiddleHigh = GameObject.Find ("MiddleHigh");
            MiddleLow = GameObject.Find ("MiddleLow");
            BottomHigh = GameObject.Find ("BottomHigh");
            BottomLow = GameObject.Find ("BottomLow");
            if (TopHigh.transform.localPosition.y == 44 || TopLow.transform.localPosition.y == 132 || MiddleHigh.transform.localPosition.y == -88 || MiddleLow.transform.localPosition.y == 0 | | BottomHigh.transform.localPosition.y == 44)
            {
                Confetti ();
                Debug.Log ("Clear !!");
            }
        }
    }
    public IEnumerator Confetti ()
    {
        ConfettiTop.SetActive (true);
        yield return new WaitForSeconds (2);
        ConfettiBottom.SetActive (true);
    }
}
What I tried

I checked if Confetti was attached to the script.

Supplementary information (FW/tool version, etc.)

The script is attached to the Text (TMP) of the canvas.

  • Answer # 1

    StartCoroutine (Confetti ());and it's solved!

  • Answer # 2

    It was solved with StartCoroutine (Confetti ()) ;!