Posts
Q&A
2D Tilemap Editor 2:00์์์
22.3.16f1๋ฒ์ ์ธ๋ฐ ๋ค๋ฅธ๋ฒ์ ์ ๋ค์ด๋ก๋ ํด์ผ ํ ๊น์?
- Likes
- 0
- Comments
- 2
- Viewcount
- 395
Q&A
์ด์์ด ๋ฐ์ฌ๊ฐ ๋์ง ์์ต๋๋ค!
public class ObjectSpawner : MonoBehaviour{ [SerializeField] private int objectSpawnCount = 30; // Start is called before the first frame update [SerializeField] private GameObject[] prefabArray; [SerializeField] private Transform[] spawnPointArray; private int currentObjectCount = 0; private float objectSpawnTime = 0.0f; void Start() { } // Update is called once per frame void Update() { if(currentObjectCount + 1 > objectSpawnCount) { return; } objectSpawnTime += Time.deltaTime; if(objectSpawnTime >= 0.5f) { int prefabIndex = Random.Range(0, prefabArray.Length); int spawnIndex = Random.Range(0, spawnPointArray.Length); Vector3 position = spawnPointArray[spawnIndex].position; GameObject clone = Instantiate(prefabArray[prefabIndex], position, Quaternion.identity); Vector3 moveDirection = (spawnIndex == 0 ? Vector3.right : Vector3.left); clone.GetComponent().Setup(moveDirection); currentObjectCount++; objectSpawnTime = 0.0f; } }} Instantiate()ํ์ฉ์์ ์์ 11:29์ ์์ ๋ฅผ ์คํํด ๋ณด์๋๋ฐclone.GetComponent().Setup(moveDirection);์์ Setup์ด ๋นจ๊ฐ์ค ๊ทธ์ด์ง๋๋['Movement2D'์๋ 'Setup'์ ๋ํ ์ ์๊ฐ ํฌํจ๋์ด ์์ง ์๊ณ , 'Movement2D' ํ์์ ์ฒซ ๋ฒ์งธ ์ธ์๋ฅผ ํ์ฉํ๋ ์ก์ธ์ค ๊ฐ๋ฅํ ํ์ฅ ๋ฉ์๋ 'Setup'์ด(๊ฐ) ์์ต๋๋ค. using ์ง์๋ฌธ ๋๋ ์ด์ ๋ธ๋ฆฌ ์ฐธ์กฐ๊ฐ ์๋์ง ํ์ธํ์ธ์.]๋ผ๋ ์ค๋ฅ ๋ชฉ๋ก์ด ๋์์
- Likes
- 0
- Comments
- 3
- Viewcount
- 801




