Javascript 数组超出范围。。有解决办法吗?
我在为我的比赛作弊。我不知道该怎么办。数组超出范围。当我运行游戏并在myStrings中键入密钥码时,它不会停止添加硬币,当我移动时,它突然终止。谢谢Javascript 数组超出范围。。有解决办法吗?,javascript,unity3d,Javascript,Unity3d,我在为我的比赛作弊。我不知道该怎么办。数组超出范围。当我运行游戏并在myStrings中键入密钥码时,它不会停止添加硬币,当我移动时,它突然终止。谢谢 private var cheatCode : String[]; var myStrings : String[] = [ "i", "d", "k", "f", "a" ]; private var index: int; public static var coins : int; private
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:
我不知道该怎么办。数组超出范围。当我运行游戏并在myStrings中键入密钥码时,它突然终止。谢谢
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:
我不知道该怎么办。数组超出范围。当我运行游戏并在myStrings中键入密钥码时,它突然终止。谢谢。在键入欺骗码后,每次调用更新方法时都会应用欺骗。如果键入作弊代码的另一个字符,则索引将递增,并导致数组超出范围。
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:
当接受作弊代码时,尝试重置索引:
if (index == cheatCode.Length) {
coins += 100;
PlayerPrefs.SetInt ("Coinss", coins);
coinsBegin++;
PlayerPrefs.GetInt("Coinss");
index = 0; //reset index
}
你已经声明了cheatCode并在更新中使用它,但是你把所有的数据都放到了mystring中。那么我该怎么做呢?请详细说明我不明白我是个新手。非常感谢您的帮助使用一个数组。你把数据放在1中,试图从2中读取数据,所以很明显,它是空的,东西坏了。我已经知道了。。谢谢你: