Created
August 29, 2019 06:50
-
-
Save IshidaGames/c1f5c9f35996863098795e16611e639c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PileUp : MonoBehaviour | |
{ | |
//InspectorからPrefabにしたCubeを入れる | |
public GameObject cube; | |
public int vertical = 5; | |
//上から見て横、X軸のオブジェクトの量 | |
public int horizontal = 5; | |
public int depth = 5; | |
int verNum; | |
int horNum; | |
int depNum; | |
void Start() | |
{ | |
Vector3 pos = new Vector3(0, 0, 0); | |
//Z軸にverticalの数だけ並べる | |
for (verNum = 0; verNum < vertical; verNum++) | |
{ | |
//X軸にhorizontalの数だけ並べる | |
for (horNum = 0; horNum < horizontal; horNum++) | |
{ | |
for (depNum = 0; depNum < horizontal; depNum++) | |
{ | |
//PrefabのCubeを生成する | |
GameObject copy = Instantiate(cube, | |
//生成したものを配置する位置 | |
new Vector3( | |
//X軸 | |
pos.x + horNum, | |
//Y軸 | |
pos.y + verNum, | |
//Z軸 | |
pos.z + depNum | |
//Quaternion.identityは無回転を指定する | |
), Quaternion.identity); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment