Wrong number of indicies inside []; inspected 2
Я не знаю, но этот код дает эти ошибки:
Array initializers can only be used in a variable or field initializer. Try using a new expression instead
Wrong number of indices inside expected 2
Как их починить?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[RequireComponent(typeof(Canvas))]
public class CheatCodeScript : MonoBehaviour
{
// Start is called before the first frame update
private void Start()
{
}
// Update is called once per frame
private void Update()
{
if (Input.anyKeyDown)
{
for (int i = 0; i < 5; i++)
{
string[] cheatCode = this.cheatCodes[i];
if (Input.GetKeyDown(cheatCode[cheatIndex]))
{
cheatIndex++;
if (cheatIndex == cheatCode.Length)
{
this.ActivateCheat(cheatCode);
cheatIndex = 0;
}
}
else
{
cheatIndex = 0;
}
}
}
}
private void ActivateCheat(string[] cheatCode)
{
if (cheatCode == cheatCodes[0])
{
this.gc.CollectItem(4);
} else if (cheatCode == cheatCodes[1]) {
this.gc.CollectItem(1);
} else if (cheatCode == cheatCodes[2]) {
this.gc.ActivateFinaleMode();
} else if (cheatCode == cheatCodes[3]) {
this.gc.player.gameOver = true;
} else if (cheatCode == cheatCodes[4]) {
base.StartCoroutine(this.gc.EnergyDrink());
}
}
private UnityEvent keyEvent = new UnityEvent();
private string[,] cheatCodes = new string[]
{
{"b","s","o","d","a"},
{"z","e","s","t","y"},
{"c","h","e","a","t"},
{"t","a","e","h","c"},
{"s","p","e","e","d"}
};
private int cheatIndex = 0;
public GameControllerScript gc;
}