void Start() { placerScript = placer.GetComponent <SpritePlacer>(); serverScript = GetComponent <ServerController>(); attachedButton = GetComponent <Button>(); attachedButton.onClick.AddListener(() => SaveTileMaps(tilemaps)); }
// Use this for initialization void Start() { GameObject newButton; SpritePlacer script = placerObject.GetComponent <SpritePlacer>(); foreach (var tile in tiles) { Debug.Log(tile.name); newButton = (GameObject)Instantiate(prefabButton, transform); newButton.GetComponent <Image>().sprite = tile; UnityEngine.Events.UnityAction action1 = () => { script.SetSelectedTileBase(tile.name); }; newButton.GetComponent <Button>().onClick.AddListener(action1);//find the button and set } }
void makeButtons() { GameObject newButton; SpritePlacer script = placerObject.GetComponent <SpritePlacer>(); //Remove all buttons currently in the content window foreach (Transform child in ContentWindow.transform) { Destroy(child.gameObject); } //Add new buttons foreach (var tile in tiles) { newButton = (GameObject)Instantiate(prefabButton, ContentWindow.transform); newButton.GetComponent <Image>().sprite = tile; UnityEngine.Events.UnityAction action1 = () => { script.SetSelectedTileBase(tile.name); }; newButton.GetComponent <Button>().onClick.AddListener(action1);//find the button and set } }