{
public GameObject asteroidPos;
public GameObject asteroidPrefab;
public float fieldRadius;
public float size;
public float movementSpeed;
public float rotationSpeed;
void Start()
{
StartCoroutine(asteroidTimer());// Asteroid Timer is called
//StartCoroutine(asteroidTimedDestructor());
populateAsteroids();
}
// Asteroid Timer
IEnumerator asteroidTimer()
{
while(true)
{
populateAsteroids();
yield return new WaitForSeconds(5);// Asteroids are called for each (5) Seconds
}
}
// Populating Asteroid
void populateAsteroids()
{
for(int i = 0; i < 20; ++i)
{
GameObject randAsteroids = (GameObject)Instantiate(asteroidPrefab, Random.onUnitSphere* fieldRadius,Random.rotation);
float size = Random.Range(2.5f, 50);
randAsteroids.transform.localScale = Vector3.one * size;
randAsteroids.rigidbody.velocity = Random.insideUnitSphere * movementSpeed;
randAsteroids.rigidbody.angularVelocity = Random.insideUnitSphere * rotationSpeed;
}
}
}
Hi, am new to unity c#, I just want asteroid to be populated for few seconds and should be destroyed. Since my game is in 3D Space, I need the asteroids to be populated in new places wherever my ship moves.Thanks in advance.