Place stars (prefabs) in random locations

Hi,

I would like to generate a 3d star field and I was thinking some prefabs of basic small white spheres with a self illuminating shader applied to them would be a good start. Whats a good way of inserting prefabs in random locations or feel free to suggest a better way to go about creating a nice 3d star field.

Thanks

How many stars are you wanting to make? I’d use billboarded simple planes (sprites) if it’s a lot

Use a particle system.

I recommend going the particle system route but if you want to try the prefab way you could use something like this

javascript

var starPrefab : GameObject; // set in the inspector
var starCount : int = 100;
var starFieldSphereSize : float = 1000;

function Start () {
    for (var i=0; i < starCount; ++i) {
        var position = Random.insideUnitSphere * starFieldSphereSize;
        Instantiate(starPrefab, position, Quaternion.identity);
    }
}