unityで、前々回前回で、簡単なブロック崩しゲームを3Dで作りました。 前回は、ボールを逃したら、ていう時にゲームオーバーの画面表示について解説したので 今回は、ブロックを全部破壊したら、ゲームクリアの画面が表示されるようにしたいと思います。

コード

▼GameManager

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement; //3)シーンを読み込む呪文の巻き物

public class GameManager : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        //1)"BlockTag"を持つオブジェクトをすべて取得
        //格納する型[] 変数名 = 格納するもの
        GameObject[] blocks = GameObject.FindGameObjectsWithTag("BlockTag");

        //2)もし0になったら
        if (blocks.Length==0)
        {
            //Debug.Log("無くなったよ");
            //Time.timeScale = 0;//ゲーム時間を止める呪文

            //4)シーンを呼び出す
            SceneManager.LoadScene("ClearScene");
        }

    }
}

コメントを残す