在我的 xna 游戏中,我有一种方法可以在地图上的随机位置创建宝箱。问题是,它把他们都吸引到了同一个地方。random 不会为 v3 点生成唯一的随机数。但是,如果我调试并逐步执行该方法,它会完美运行。
void CreateTreasure()
{
for (int i = 0; i < 20; i++)
{
Random random = new Random();
Treasure t = new Treasure(new Vector3((float)random.Next(0, 600), 0, (float)random.Next(600)));
treasureList.Add(t);
}
}
在平局中我循环
foreach (Treasure t in treasureList)
{
DrawModel(treasure, Matrix.Identity * Matrix.CreateScale(0.02f) * Matrix.CreateTranslation(t.Position));
PositionOnMap(ref t.Position);
}
PositionOnMap 只是获取位置并调整 Y 以使模型位于高度图上。有什么想法吗?