개별 콜라이더에 Rigidbody와는 다른 물리효과를 줄 수 있다.



List<int> availableLanes = new List<int> { 0, 1, 2 };
private void Start()
{
SpawnFences();
spawnApple();
spawnCoin();
}
void SpawnFences()
{
int fencesToSpawn = Random.Range(0, lanes.Length);
for(int i = 0; i < fencesToSpawn; i++)
{
if (availableLanes.Count <= 0) break;
int selectedLane = SelectLane();
Vector3 spawnPosition = new Vector3(lanes[selectedLane], transform.position.y, transform.position.z);
Instantiate(fencePrefab, spawnPosition, Quaternion.identity, this.transform);
}
}
void spawnApple()
{
if(Random.value > appleSpawnChance) return;
if (availableLanes.Count <= 0) return;
int selectedLane = SelectLane();
Vector3 spawnPosition = new Vector3(lanes[selectedLane], transform.position.y, transform.position.z);
Instantiate(applePrefab, spawnPosition, Quaternion.identity, this.transform);
}
배열을 써서 생성할 수도 있음.