I below code :
public async void GenerateCollectionData()
{
DataClassArray = new DataClass[bookCatogaryObject.Data.Rows.Count];
for (int i = 0; i < bookCatogaryObject.Data.Rows.Count; i++)
{
DataClassArray[i] = new DataClass();
DataClassArray[i].collectionDataClass = new CollectionDataClass[bookCatogaryObject.Data.Rows[i].String.Count];
DataClassArray[i].categaryPrefabObject = bookCatogaryPrefabObjects[i];
for (int m = 0; m < bookCatogaryObject.Data.Rows[i].String.Count; m++)
{
GameObject obj = DataClassArray[i].categaryPrefabObject.gameObject;
GameObject childObj = GetChildGameObject(obj, "Content");
GameObject collectionImageContainer = new GameObject();
collectionImageContainer.AddComponent<Image>();
collectionImageContainer.AddComponent<JMRUIPrimaryButton>();
//collectionImageContainer.AddComponent<InteractionManager>();
collectionImageContainer.transform.parent = childObj.transform;
collectionImageContainer.GetComponent<Image>().sprite =
Sprite.Create(
DataClassArray[i].collectionDataClass[m].collectionImage,
new Rect(0.0f, 0.0f, DataClassArray[i].collectionDataClass[m].collectionImage.width,
DataClassArray[i].collectionDataClass[m].collectionImage.height),
new Vector2(0.5f, 0.5f)
);
RectTransform setValues = collectionImageContainer.GetComponent<RectTransform>();
setValues.localPosition = new Vector3(0f, 0f, 0f);
setValues.localRotation = Quaternion.identity;
setValues.localScale = new Vector3(1f, 1f, 1f);
DataClassArray[i].collectionDataClass[m].collectionButton = collectionImageContainer;
collectionImageContainer.GetComponent<JMRUIPrimaryButton>().
OnClick.AddListener
(
delegate ()
{
OnClickEvent(DataClassArray[i].collectionDataClass[m].id);
}
);
//StartCoroutine(BookCollection(requestString, str));
}
}
}
public void OnClickEvent(string tempString)
{
Debug.Log(tempString);
}
Im trying to get _id associated to that specific button which is clicked When I execute the above code I get "IndexOutOfRangeException: Index was outside the bounds of the array." error at line OnClickEvent(DataClassArray[i].collectionDataClass[m].id); What might be the issue?