0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

三重のfor文でオブジェクトを沢山出す

Posted at

スクリーンショット 2022-07-11 171056.png
まずcubeをヒエラルキーに出しassetsの中にドラッグアンドドロップしてプレハブ化したら以下のコードを書きます。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Boxs : MonoBehaviour
{
    public GameObject Box;
    Vector3 BoxPos;
    void Start()
    {
        for (float x = 0.0f; x < 50.0f; x += 2.0f)
        {
            for (float y = 0.0f; y < 50.0f; y += 2.0f)
            {
                for (float z = 0.0f; z < 50.0f; z += 2.0f)
                {
                    BoxPos = new Vector3(x, y, z);
                    Instantiate(Box, BoxPos, Quaternion.identity);
                }
            }
        }
    }
}

ヒエラルキーに空のオブジェクトを出してBoxs.csをアタッチして、プレハブ化したcubeをボックスにドラッグアンドドロップしましょう。
image.png
あとは実行ボタンを押してcubeが沢山出ていることを確認しましょう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?