Adding a texture to array textures?!

Hey guys! Im trying to make a thing where in one script I make an array for button(skill bar), so if I enter 3 there will be 3 buttons with their own textures, and in another script I want to add a button and then assign a texture to that new button. It keeps telling me Array index out of range! What should I do?

Skill bar Script:
#pragma strict

public var count : int;

public var SkillsNum : boolean[] = [];
public var SkillsPos : Rect[];
public var SkillsNames : String[];
public var SkillsTexture : Texture2D[];

function Start () {

}

function Update () {
SkillsPos = new Rect[count];
SkillsNum = new boolean[count];
SkillsNames = new String[count];
SkillsTexture = new Texture2D[count];

}

function OnGUI () {
	for(var i : int = 0; i < SkillsNum.length; i++){
		SkillsNum _= GUI.Button(Rect(Screen.width - (Screen.width * 0.6) + 52 * i, Screen.height - (Screen.width * 0.05), 50,50),SkillsTexture*);*_

_ if(SkillsNum*){*_

* }*
* }*
}
other script(part of it, rest is the EquipmentEffect from Brakeys):
var texture : Texture2D;

Player.GetComponentInChildren(SkillBar_02).count += 1;
Player.GetComponentInChildren(SkillBar_02).SkillsTexture = texture;
“count” determines how many buttons there are.

On how many I see, you change the array size, but you don’t change an array. And it isn’t clear that for the variable “i” in the second piece of a code. I will a little change your code and I will add comments. First script by name “SkillBars_02”:

 #pragma strict

 public var count: int;

 public var SkillsNum: boolean[];
 public var SkillsPos: Rect[];
 public var SkillsNames: String[];
 public var SkillsTexture: Texture2D[];

 function Start () {
  //Here initialization your arrays. It isn't necessary to create each frame them as Update ()
  SkillsPos = new Rect[count];
  SkillsNum = new boolean[count];
  SkillsNames = new String[count];
  SkillsTexture = new Texture2D[count];
  //After you fill arrays with their values
 }

 function Update () {

 }

 function OnGUI () {
  for(var i: int = 0; i < SkillsNum.Length; i++) {
   SkillsNum _= GUI.Button(Rect(Screen.width - (Screen.width * 0.6) + 52 * i, Screen.height - (Screen.width * 0.05), 50,50),SkillsTexture*);*_

if(SkillsNum*) {*

}
}
}
//Create new function, which addind new texture to array
function myAddTexture(tpTex: Texture2D, tpRect: Rect, tpName: String) {
Debug.Log("Value count = " + count + " value Length = " + SkillsTexture.Length);
//Values “count” and “Length” shall be equal
count++; //increase value of count elements of arrays
//create temp array for new textures
var tpSkillsTexture: Texture2D[] = new Texture2D[count];
//create temp array for other elemets skills
var tpSkillsPos: Rect[] = new Rect[count];
var tpSkillsNum: boolean[] = new boolean[count];
var tpSkillsNames: String[] = new String[count];
//Fill arrays previos data and last index new data
for(vat i: int = 0; i < count - 1; i++) {
Debug.Log("Store element i = " + i);
tpSkillsTexture = SkillsTexture*;*
tpSkillsPos = SkillsPos*;*
tpSkillsNum = SkilsNum*;*
tpSkillsNames = SkillsNames*;*
}
//And add new skill
tpSkillsTexture[count - 1] = tpTex;
tpSkillsPos[count - 1] = tpRect;
tpSkillsNum[count - 1] = false;
tpSkillsNames[count -1] = tpName;
//Now we remember new reference
SkillsTexture = tpSkillsTexture;
SkillsPos = tpSkillsPos;
SkillsNum = tpSkillsNum;
SkillsNames = tpSkillsNames;
}
And second script(you in it shall have texture, a rect and a name of a new skill), more precisely only its part.
Player.GetComponentInChildren(SkillBar_02).myAddTexture(texture, Rect(50, 100, 50, 50), “YourSkillName”);
In the second part it isn’t necessary to change count value. It changes as myAddTexture(). Rect and Name you can set any which you think the correct. I hope that it will help you.