ステージ自動生成システムを作る







Stageの自動生成
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// (ポイント)開発モードの段階でもコードを実行することができる。
// ★追加
[ExecuteAlways]
public class StageCreate : MonoBehaviour
{
private GameObject blockBox;
// 二重配置の防止(ポイント)
public bool isSet = false;
void Start()
{
if (!isSet)
{
blockBox = new GameObject("BlockBox"); // 指定した名前でCreate Emptyオブジェクトを作成
for (int i = -8; i < 8; i++)
{
for (int j = -8; j < 8; j++)
{
GameObject blockPrefab = (GameObject)Resources.Load("Block");
GameObject block = Instantiate(blockPrefab, new Vector3(i, 0.1f, j), Quaternion.identity);
// 動的に親子関係の設定(ポイント)
block.transform.parent = blockBox.transform;
}
}
}
// 上記の処理が完了したら「true」に変更
isSet = true;
}
}







【2021版】TowerD Ⅱ(全17回)
他のコースを見る






Stageの自動生成
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// (ポイント)開発モードの段階でもコードを実行することができる。
// ★追加
[ExecuteAlways]
public class StageCreate : MonoBehaviour
{
private GameObject blockBox;
// 二重配置の防止(ポイント)
public bool isSet = false;
void Start()
{
if (!isSet)
{
blockBox = new GameObject("BlockBox"); // 指定した名前でCreate Emptyオブジェクトを作成
for (int i = -8; i < 8; i++)
{
for (int j = -8; j < 8; j++)
{
GameObject blockPrefab = (GameObject)Resources.Load("Block");
GameObject block = Instantiate(blockPrefab, new Vector3(i, 0.1f, j), Quaternion.identity);
// 動的に親子関係の設定(ポイント)
block.transform.parent = blockBox.transform;
}
}
}
// 上記の処理が完了したら「true」に変更
isSet = true;
}
}







ステージ自動生成システムを作る