今のデータ構造で比較できそうな部分だと、
using UnityEngine;
using System.Linq;
public enum Type
{
black,
white
}
// これがBlocksController
public class Test2 : MonoBehaviour
{
public Type type;
}
// これがStageManager
public class test : MonoBehaviour
{
private void Start()
{
// ステージのデータはこんな感じのものが作られている
var blockTable = new Type[,] {
{ Type.black, Type.black, Type.black },
{ Type.black, Type.black, Type.black },
{ Type.black, Type.black, Type.black },
};
// 操作されるゲームオブジェクトが持つデータはこんな感じになっている
var BlocksController = new Test2[,] {
{ new Test2 {type = Type.black }, new Test2 {type = Type.black }, new Test2 {type = Type.black } },
{ new Test2 {type = Type.black }, new Test2 {type = Type.black }, new Test2 {type = Type.black } },
{ new Test2 {type = Type.black }, new Test2 {type = Type.black }, new Test2 {type = Type.black } },
};
// リンク使いたい病だと
if (blockTable.Cast<int>()
.SequenceEqual(BlocksController.Cast<Test2>().Select(_ => _.type).ToArray()
.Cast<int>())) {
Debug.Log("正解");
}
else {
Debug.Log("不正解");
}
}
}
おとなしくfor文で回したらこんな感じで判定できるのではないでしょうか?
bool isSuccess = true;
for (int y = 0; y < blockTable.GetLength(1); y++)
{
for (int x = 0; x < blockTable.GetLength(0); x++)
{
if (blockTableobj[x, y].type != blockTable[x, y]) isSuccess = false;
}
}
if (isSuccess) {
Debug.Log("正解");
} else {
Debug.Log("不正解");
}
退会済みユーザー
2021/08/19 17:02
退会済みユーザー
2021/08/19 21:27 編集
退会済みユーザー
2021/08/19 21:41