目前我正在做以下事情,我确信这是一种缓慢的方式。基本上我穿过一个网格并确定a)是否存在一颗星星,b)如果有一颗星星是什么类型。我认为我应该做的是使用我的已知值(例如 current_star_density * 0.25)并使用它来绘制一系列点。我想我不确定的部分是当我绘制该数量时如何防止重复。
任何帮助将不胜感激。这是代码的相关部分。
for (var z = 0; z < gridZ; z++)
{
for (var x= 0; x < gridX; x++)
{
star_chance = Random.value * 1000; // * 1000
if (star_chance <= current_star_density)
{
star_class = Random.value * 100;
if (star_class <=1) // add in the other star types etc
{
new_star = Instantiate(prefab_o, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("O:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=2)
{
new_star = Instantiate(prefab_b, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("B:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=5)
{
new_star = Instantiate(prefab_a, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("A:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=10)
{
new_star = Instantiate(prefab_f, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("F:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=20)
{
new_star = Instantiate(prefab_g, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("G:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=40)
{
new_star = Instantiate(prefab_k, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("K:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
else if (star_class <=80)
{
new_star = Instantiate(prefab_m, Vector3(x * 10 + transform.position.x - 500, 0, z * 10 + transform.position.z - 500), Quaternion.identity);
new_star.transform.parent = this.transform;
new_star.name = String.Format("M:{0}.{1}:{2}.{3}",galaxy_X,x,galaxy_Y,z);
}
}
}
}