1

I have Canvas and all UI components are put inside as shown in the image. There is a ScriptObject to implement C# script (Historyscript.cs) for handling the UI. Historyscript.cs is attached to ScriptObject and Dropdown has link to the script and Dropdown component is working. Now I like to detect Dropdown component is clicked in Unity.

enter image description here

What I do is in the Historycanvas,

public void OnPointerClick(BaseEventData eventData) is added.

using UnityEngine.EventSystems;
public class Historycanvas : MonoBehaviour, IPointerClickHandler
{
    void Start(){}

    public void OnPointerClick(BaseEventData eventData)
    {
        Debug.Log(" was selected");
    }

    // Update is called once per frame  
    void Update () {

    }
}

To have linked that public void OnPointerClick(BaseEventData eventData) to Dropdown object, I added ScriptObject to Dropdown's function link.

enter image description here

Inside we can find Historycanvas class, but there is no OnPointerClick function to link. What could be the issue?

enter image description here

EDIT:

This question is different from Programmer's link as he implemented Callback function, but my implementation is different. He used onValueChanged(), but I like to implement OnPointerClick() or onSelect(). I can't add AddListener() to OnPointerClick() or onSelect().

batuman
  • 7,066
  • 26
  • 107
  • 229
  • You use the `onValueChanged` for that which takes `int` as parameter not `BaseEventData`. See #5 from the duplicate for full example. By the way, this is C# not unityscript. – Programmer Oct 15 '17 at 00:46
  • @Programmer I am going to detect the Dropdown is clicked to drop, onValueChanged is triggered once one of the options in the dropdown is clicked. I can't use that. – batuman Oct 15 '17 at 01:02
  • If you just want to detect if the drop down is clicked then read the whole answer. #1 has many callback functions and `OnPointerClick` is what you are looking for. Just attach it to the drop down object. *You must implement **`IPointerClickHandler`** in order for that function to be called* – Programmer Oct 15 '17 at 01:14
  • Yes how to attach is my question. I am trying to attach, but I can't find function. Please read my question. – batuman Oct 15 '17 at 01:27
  • Your second sentence and current code does not reflect what's in the original question. I find it annoying that you are changing things in your question and also with the code from the duplicate. Please roll back the question to what it was before then add **EDIT** to your question followed by your new code you added after I flagged it as duplicate then clearly mention what's not working at this point. – Programmer Oct 15 '17 at 01:34
  • No I just change, OnSelect to OnPointerClick only. The whole idea is still the same, how to link the function to an object. My query is very straightforward, "how to link the function to object". You are making things complicated linking to your old post. – batuman Oct 15 '17 at 01:36

0 Answers0