私のゲームのカンニングをしています。私は何をすべきか分からない。配列が範囲外です。私はゲームを実行し、myStringでキーコードを入力するとコインの追加をやめ、移動すると突然終了しました。ありがとうございます。配列が範囲外です。解決策はありますか?
private var cheatCode : String[];
var myStrings : String[] = [ "i", "d", "k", "f", "a" ];
private var index: int;
public static var coins : int;
private var coinsBegin : int;
function Start() {
coins = PlayerPrefs.GetInt("Coinss");
cheatCode = myStrings;
index=0;
}
function Update() {
if (Input.anyKeyDown) {
if (Input.GetKeyDown(cheatCode[index])) {
index++;
}
else {
index = 0;
}
}
if (index == cheatCode.Length) {
coins += 100;
PlayerPrefs.SetInt ("Coinss", coins);
coinsBegin++;
PlayerPrefs.GetInt("Coinss");
}
}
function OnGUI() {
GUI.Label (Rect (20, 20, 200, 40), "score: " +PlayerPrefs.GetInt("Coinss"));
}
//Error:
This one is the picture of the error
私は何をすべきかを知りません。配列が範囲外です。私はゲームを実行し、私は突然終了したmyStringsでキーコードを入力します。ありがとう。
私は何をすべきか分かりません。配列が範囲外です。私はゲームを実行し、私は突然終了したmyStringsでキーコードを入力します。ありがとう。
あなたは 'cheatCode'宣言したと' Update'でそれを使用されていますが、 'myStrings'にすべてのデータを置きます。 – ssube
どうすればいいですか?私は初心者を理解していないことを詳しく教えてください。あなたの助けを大変ありがとうございます – aikachiqq
1つの配列を使用してください。 #1にデータを入れて#2から読み込もうとしているので、明らかに空であり、物事が壊れています。 – ssube