I created an empty object called SpawnManager. I wrote the code for instantiating and moving and added prefabs. But since the instantiated objects are not cloned as children of SpawnManager object, I cannot move them. What can I do to move the instantiated objects?
public GameObject[] obstaclePrefab;
private float startDelay=2;
private float repeatRate=2;
public float spawnPosX=5;
public float spawnPosY=15;
void Start()
{
InvokeRepeating("SpawnObstacle", startDelay, repeatRate);
}
void SpawnObstacle()
{
Vector3 spawnPos=new Vector3(Random.Range(-spawnPosX, spawnPosX),Random.Range(-spawnPosY,spawnPosY),-5);
int spawnIndex = Random.Range(0,obstaclePrefab.Length);
Instantiate(obstaclePrefab[spawnIndex], spawnPos, obstaclePrefab[spawnIndex].transform.rotation);
}
↧