I have made a scroll view and using Grid to arrange sprites.
I add sprite dynamically ,by using prefab.
Sprite items create successfully but when mouse hover sprite applied by code disappear and original sprite appear … help to get rid from this problem …
public GameObject RootGrid;
public GameObject ItemPref;
GameObject Obj;
// Use this for initialization
void Start () {
for (int i=1; i<=12; i++) {
GameObject item=NGUITools.AddChild(RootGrid,ItemPref);
item.name= "item" + i;
}
RootGrid.transform.parent.GetComponent<UIScrollView> ().ResetPosition ();
RootGrid.GetComponent<UIGrid> ().Reposition ();
Debug.Log("Child Objects: " + CountChildren(transform));
Debug.Log ("From Add Child Script");
}
int CountChildren(Transform a)
{
int childCount = 0;
foreach (Transform b in a)
{
foreach (Transform c in b){
Obj=c.gameObject;
UISprite yourSprite =Obj.GetComponent<UISprite>();
yourSprite.spriteName = "NGUI";
Debug.Log("Child: "+b);
childCount ++;
}
}
return childCount;
}