Having trouble with array of GameObjects.
a piece of code:
private string[] weap = new string[] {"p_01","smg_01","sg_01"};
public GameObject[] guns;
void Start () {
guns[0] = Resources.Load("Prefab/weapons/" + weap[0], typeof(GameObject)) as GameObject;
guns[1] = Resources.Load("Prefab/weapons/" + weap[1], typeof(GameObject)) as GameObject;
guns[2] = Resources.Load("Prefab/weapons/" + weap[2], typeof(GameObject)) as GameObject;}
And error:
IndexOutOfRangeException: Array index is out of range. (wrapper stelemref) object:stelemref (object,intptr,object) init.Start () (at Assets/Resources/script/init.cs:23)
line 23: guns[0] = Resources.Load(“Prefab/weapons/” + weap[0], typeof(GameObject)) as GameObject;
I have no ideas why I have this error =(