我有这段代码
string[,] table = new string[104, 15];
int xIndex = -1;
int yIndex = 0;
string newPrevious = "placeholder";
//P = BLUE, B = RED, T = GREEN
string[] strData = {"P ,B ,P ,P B,B ,P ,B ,T ,P ,P "};
//conditions
string[] scoreBoard = new string[]
{"P ", "B ", "T ",
"P B","B P" };
string OriginalData = "";
void Start(){
StartCoroutine ("Win_Log");
}
IEnumerator Win_Log(){
yield return new WaitForEndOfFrame ();
for (int i = 0; i < strData.Length; i++) {
OriginalData += strData [i];
OriginalData += ",";
}
string[] newNewData = OriginalData.Split (',');
string result = "";
foreach (string newStrData in newNewData) {
Debug.Log ("This is the data : " + newStrData);
GameObject o = Instantiate (prefab_gameobject) as GameObject;
o.transform.SetParent (pos_big_road);
o.transform.localScale = Vector3.one;
img = (RawImage)o.GetComponent<RawImage> ();
//check the length so that it won't throw an exception
if (newStrData.Length > 1) {
//get only the first letter of the value P,B,T
result = newStrData.Substring (0, 1);
}
else {
result = "";
}
#region BIG ROAD
if(table.GetLength(0) < xIndex){
break;
}
if (result.Equals (newPrevious) || result.Equals("T") && yIndex < table.GetLength (1)) {
yIndex += 1;
table [xIndex, yIndex] = result;
}
else if(newPrevious.Equals("T") && yIndex < table.GetLength (1)){
yIndex += 1;
table [xIndex, yIndex] = result;
}
else
{
xIndex += 1;
yIndex = 0;
table [xIndex, yIndex] = result;
}
newPrevious = result ;
o.transform.localPosition = new Vector3 (xIndex * 93, yIndex * -93, 0f);
我的问题是这个
正如您在上一栏
中看到的那样红,绿,青,蓝
它的值是
//P = BLUE, B = RED, T = GREEN
string[] strData = {"P ,B ,P ,P B,B ,P ,B ,T ,P ,P "};
BLUE, BLUE
必须位于下一行,因为它不等于newPrevious
变量,我所说的RED
值高于GREEN
值。所以你必须对此感到困惑,但是GREEN
值更像是被忽视我的意思被忽视是这样的
现在最后一列的值是
蓝色,蓝色,绿色,红色,红色
其值为
//P = BLUE, B = RED, T = GREEN
string[] strData = {"P ,B ,P ,P B,B ,P ,P ,T ,B ,B "};
正如您在图片中看到的那样,RED, RED
必须位于下一行,因为它不等于newPrevious
变量,而我所说的BLUE
上面的GREEN
newPrevious
值。
我在这里可以实现的是将GREEN
的值放到一个变量中,在该变量中它将值存储在newPrevious
之前,这样我就可以将它与新的RED
进行比较{1}}值。
例如,上面的图片具有值
红色,绿色,蓝色,蓝色
我想保存BLUE
值,以便我可以将其与xIndex
值进行比较,以便我可以使用yIndex
代替(?i)(?:0x(?:[0-9a-f]+(?:'?[0-9a-f]+)*)|0b(?:[10]+(?:'?[10]+)*)|\d+(?:'?\d+)*)(?:ull|ll|ul|l|u)?
第一个图像预期输出必须是此
第二个图像预期输出必须像这样
答案 0 :(得分:2)
取另一个变量“previous”。将它设置为newPrevious的值,就像现在一样,并在下一次迭代中检查它是否已更改。
替换此
newPrevious = result ;
有了这个
if(!result.Equals("T"))
newPrevious = result ;