穴埋め法(迷路)を使って、クォータービューのマップを自動生成するスクリプトを書いています。
自己流のやり方でやったせいか、浮島のような穴が出来てしまいます。その穴を埋めるメソッドを書いたのですが、なぜか、同じ座標に複数のオブジェクトが生成されてしまいます。Linqを使えば重複要素を削除出来ると調べたら出たのですが、Linqの使い方がいまいちよく分かりません。
穴を埋めるメソッド↓
C#
1void GenerateMap() 2 { 3 foreach (Vector3 pos in listpos) 4 { 5 //pos 6 CenterPos = new Vector3(pos.x - 1, pos.y - 0.5f, 0); 7 Vector3 CenterPos2 = new Vector3(pos.x - 2, pos.y, 0); 8 Vector3 CenterPos3 = new Vector3(pos.x - 2, pos.y - 1, 0); 9 Vector3 CenterPos4 = new Vector3(pos.x, pos.y - 1, 0); 10 foreach (Vector3 pos2 in listpos) 11 { 12 if (pos2 == CenterPos2) 13 { 14 foreach (Vector3 pos3 in listpos) 15 { 16 if (pos3 == CenterPos3) 17 { 18 foreach (Vector3 pos4 in listpos) 19 { 20 if (pos4 == CenterPos4) 21 { 22 anaume = Instantiate(Tile, CenterPos, Quaternion.identity); 23 objects = GameObject.Find("Anaume"); 24 anaume.transform.parent = objects.transform; 25 anaume.name = "x_" + anaume.transform.position.x + "_y_" + anaume.transform.position.y; 26 Renderer renderer = anaume.GetComponent<Renderer>(); 27 float PosY = anaume.transform.position.y; 28 float suuzi = PosY * 1000; 29 renderer.sortingOrder -= (int)suuzi; 30 } 31 } 32 } 33 } 34 } 35 } 36 } 37 }
エラーなどは出ていません。
重複しないように生成する方法を知りたいです。
回答お願いします。
あなたの回答
tips
プレビュー