Greetings, I have normally used something like this to make a sprite clickable in my current project: Code (CSharp): clickableThing.AddComponent<scriptR>(); clickableThing.GetComponent<scriptR>().setReference(r); clickableThing.AddComponent<BoxCollider2D>(); *ScriptR contains a reference to thing and an onClick function. However this won't work in the UI. I've found I need to use a button and add a onClick listener I'm having trouble getting it to work right. If I add the following it still fails: Code (CSharp): clickableThing.AddComponent<Button>(); clickableThing.GetComponent<Button>().onClick.AddListener(() => {clickableThing.GetComponent<scriptR>().copyOfOnClickFunction}) What's the right way of doing this for things in the UI?
Something here will probably help you best https://unity3d.com/learn/tutorials/topics/user-interface-ui
The UI does not use the OnClick methods. Instead it uses interfaces. You need to make your scriptR implement the appropriate IPointerClickHandler interface. http://docs.unity3d.com/Manual/SupportedEvents.html