Here is my Code. The Function doSomething() wont execute on button click. Can you tell me what i am doing wrong. Thanks
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Arrow : MonoBehaviour {
public GameObject myarrow;
private Button myButton;
void Start () {
myarrow = GameObject.Find("Arrow_Sprite");
myarrow.AddComponent<Button> ();
// myarrow.GetComponent<Button> ().enabled = true;
// myButton.GetComponent<GameObject> ().gameObject = myarrow.gameObject;
// myButton = myarrow.GetComponent<UnityEngine.UI.Button> ();
myarrow.GetComponent<Button>().onClick.AddListener (delegate {
doSomething();
});
myarrow.GetComponent<Button>().enabled = true;
}
public void doSomething()
{
myarrow.transform.position = new Vector2 (5, 2);
}
// Update is called once per frame
void Update () {
}
}