using UnityEngine;
public class Test : MonoBehaviour
{
public Transform hero;
public GameObject treePrefab;
public int width;
public int height;
// Start is called before the first frame update
void Start()
{
GenerateWall();
}
void GenerateWall()
{
var wallParent = new GameObject("Walls").transform;
wallParent.transform.position = hero.position;
float evenOffset = (width % 2 == 0) ? 0.5f : 0; //์ง์์ผ๋ ์์ธ์ฒ๋ฆฌ1
for (int i = 0; i < width; i++)
{
Instantiate(treePrefab, new Vector3(i - width / 2 + evenOffset, (float)height /2) + hero.position, Quaternion.identity, wallParent);
Instantiate(treePrefab, new Vector3(i - width / 2 + evenOffset, -(float)height /2) + hero.position, Quaternion.identity, wallParent);
}
evenOffset = (height % 2 == 0) ? 0.5f : 0; //์ง์์ผ๋ ์์ธ์ฒ๋ฆฌ2
for (int i = 0; i < height; i++)
{
Instantiate(treePrefab, new Vector3((float)width / 2 ,i - height / 2 + evenOffset) + hero.position, Quaternion.identity, wallParent);
Instantiate(treePrefab, new Vector3(-(float)width /2, i - height / 2 + evenOffset) + hero.position, Quaternion.identity, wallParent);
}
}
}
ํ์ฐ.. ํํ๊ธ์ย ๊ฐ๊น์ด ์ฝ๋์ง๋ฌธ ์ ๋ต๋ณ ์ํ๋๋ฐ ์ด๋ฒ๋ง์
๋๋ค.
์ง์ง ๋์ถฉ์งฌ
์ด์ ๋๋ฌด๋ฅผ ์ฌ๋ฌ๊ฐ ์ํํ๋๊ฒ ์๋๋ผ ๋๋ฌด ํ๋๋ฅผ ๊ธธ๊ฒ ๋๋ ค์ ์ํํ ์ ์๋๋ ์๊ธฐ ๋ ์์จ๋ค