- Home /
button on click event and prefab items
I have some objects generated via script through a prefab
Object prefab = new Object();
prefab = AssetDatabase.LoadAssetAtPath("Assets/prefab/enamy.prefab", typeof(GameObject));
Enamies[i] = Instantiate(prefab, this.transform.position, Quaternion.identity) as GameObject;
and I have a button gui who's on click event I want to call the on nextTurn of the items made by the prefab, the only problem is it is calling the nextTurn event of the prefab and not the items created by the prefab.
Comment
Answer by kevinspawner · Jan 08, 2015 at 03:29 AM
You need to assign the created prefabs to new variable and use that varibale to call that in your code.
it seems a little odd that I can not tie it in to the on click event, I suppose I can put another function someplace else that loops through the items, it is just going to feel weird with the events firing differently for the static created and dynamically created game objects.