Answer the question
In order to leave comments, you need to log in
How to set a delegate to a Unity button when creating it?
I make a kind of inventory object by destroying the object and creating a Prefab and setting up its parts.
public GameObject InventoryItem;
public Sprite sprites;
public void Use()
{
GameObject toy = Instantiate(InventoryItem,GameObject.Find("Inventory").transform);
toy.GetComponent<Image>().sprite = sprites;
toy.AddComponent(typeof(Axe));
//От тута не происходит то что я себе представляю.
toy.transform.Find("ButtonUse").GetComponent<Button>().onClick.AddListener(delegate() { toy.GetComponent<Axe>().UseOnPick(); });
Destroy(gameObject);
}
public void UseOnPick()
{
Text textField = GameObject.Find("Text").GetComponent<Text>();
textField.text = "Это обычный Топор";
new WaitForSeconds(5);
textField.text = "";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question