|
public UIGrid grid;
int count = 1;
void OnClick()
{
/* UIAtlas atlas = Resources.Load("Fantasy Atlas", typeof(UIAtlas)) as UIAtlas;
GameObject parent = GameObject.Find("Grid");
UISprite sprite = NGUITools.AddSprite(parent,atlas,"Window");
sprite.MakePixelPerfect();
grid.Reposition();*/
GameObject obj = (GameObject)Instantiate(Resources.Load("Item"));
obj.name = "Item" + count;
obj.transform.parent = GameObject.Find("Grid").transform;
//这里需重置一下坐标,因为创建时是在外部创建的
GameObject item = GameObject.Find(obj.name);
item.transform.localPosition = new Vector3(0,0,0);
item.transform.localScale= new Vector3(1,1,1);
count++;
grid.Reposition();
}
|
|