Question by
mcmalonzo · Oct 12, 2017 at 06:50 PM ·
indexing-array
IndexOutOfRangeException: Array index is out of range.
hello pro-grammers! I've a problem with this savescript, when I have multiple clones of the same game object it says IndexOutOfRangeException: Array index is out of range. the script is the following:
public void Battlebutton()
{
int i = woodcun + stonecn + goblinhn;
int a = 0;
counter = new string[i];
savefile = new string[i];
ssfw = new string[woodcun];
foreach (string counw in counter)
{
GameObject[] wcs = GameObject.FindGameObjectsWithTag("woodcutter");
foreach (GameObject wc in wcs)
{
string sfw = savefile[a]; //problem is here.
PlayerPrefs.SetString("save" + wc.name, sfw);
sfw = JsonUtility.ToJson(wc.GetComponent<WoodcutterBeha>());
ssfw[a] = sfw;
a = a + 1;
}
} Thanks from now for the answer!
Comment
Your answer
Follow this Question
Related Questions
Is it possible to have one script to call upon levels please help!! 2 Answers
How to GetComponent for SteamVR_TrackedObj when script not attached to controller 0 Answers
[ANSWERED] IndexOf and LastIndexOf both returning -1 when an item is on the list. 1 Answer
Trouble With Image Loading Script 1 Answer