2012-09-03 126 views
0

我正在使用Unity Game Engine,並且遇到了一些代碼問題。爲什麼G == G返回false?

function NoteDecision(n :String) { 
    Debug.Log("-"+n+"-"); // This is returning -G- which means its just "G" 
    Debug.Log(n=="G"); // This is returning false, although n is G 
    switch (n){ 
     case "G": 
      Instantiate(GreenNote, SGreenNote.position, SGreenNote.rotation); break; 
     case "R": 
      Instantiate(RedNote, SRedNote.position, SRedNote.rotation); break; 
     case "Y": 
      Instantiate(YellowNote, SYellowNote.position, SYellowNote.rotation); break; 
     case "B": 
      Instantiate(BlueNote, SBlueNote.position, SBlueNote.rotation); break; 
     case "O": 
      Instantiate(OrangeNote, SOrangeNote.position, SOrangeNote.rotation); break; 
     default : Debug.Log("There is a problem here..."); 
    } 
} 

所以我的代碼沒有改變,雖然我可以告訴你什麼改變了,因爲它停止工作。

變量n保存我使用String.Split()分割的字符串的後半部分。之前,它在逗號前面舉行了下半場。

Y,023.19592 // this is what it used to look like 
023.19592,Y // this is what it looks like now 

所以無論如何,這裏是代碼

note = lines[position].Split(","[0]); // this is where it gets split. 
NoteDecision (note[1]); // calling the function above. 

所以沒有任何人知道是什麼問題,或者解決方案的其他片段?

+0

標籤團結是微軟統一。請不要濫用它。 –

+0

@Curious Didnt我已經在每個案例的最後添加了休息?也許我沒有做好,可有人幫助我嗎? –

+0

@indiv它看起來很有希望,但是當我去和刪除:字符串,它沒有區別,我超級難倒..這應該工作! –

回答

0

你應該使用:

Debug.Log(n.Equals("G")); // this will return true 
+0

考慮通過提供一個理由來解釋爲什麼OP應該使用您提出的解決方案。單個句子的答案並不是非常有用:) – Sujay

+0

該解決方案適用於Android Java,但OP的代碼應該可以在Unity JavaScript,AFAIK中使用。 – jeff