So. Im creating GUI Image like this:
GameObject obj = new GameObject("Image");
obj.transform.SetParent(GameObject.Find("Canvas").transform);
obj.AddComponent<Image>();
obj.AddComponent<Interactable>();
Here is Interactable code:
public class Interactable : MonoBehaviour {
void OnMouseUpAsButton() { Debug.Log ("click!"); }
}
And when im clicking on the image nothing happends. With other objects its do the trick, but not when Image in it. How can i do this?
P.S. Adding BoxCollider2D to the object doesn’t help.