Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug AddListener in DebugUIBuilder.cs not working

Discussion in 'VR' started by Myla9, Sep 7, 2022.

  1. Myla9

    Myla9

    Joined:
    Jul 7, 2022
    Posts:
    1
    Hello everyone!
    I'm new to working with VR on unity. I'm trying to open a VR project while using the Oculus Quest 2 as a headset, but i keep receiving the following message:

    Assets\Oculus\SampleFramework\Core\DebugUI\Scripts\DebugUIBuilder.cs(312,22): error CS1061: 'object' does not contain a definition for 'AddListener' and no accessible extension method 'AddListener' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

    and it referes to this segment of code:

    Code (CSharp):
    1.  public RectTransform AddButton(string label, OnClick handler = null, int buttonIndex = -1, int targetCanvas = 0, bool highResolutionText = false)
    2.   {
    3.     RectTransform buttonRT = null;
    4.     if(buttonIndex == -1)
    5.         buttonRT = GameObject.Instantiate(buttonPrefab).GetComponent<RectTransform>();
    6.     else
    7.         buttonRT = GameObject.Instantiate(additionalButtonPrefab[buttonIndex]).GetComponent<RectTransform>();
    8.  
    9.     Button button = buttonRT.GetComponentInChildren<Button>();
    10.     if(handler != null)
    11.       button.onClick.AddListener(delegate { handler(); });
    12.  
    13.  
    14.       if(highResolutionText){
    15.         ((TextMeshProUGUI)(buttonRT.GetComponentsInChildren(typeof(TextMeshProUGUI), true)[0])).text = label;
    16.       }
    17.       else{
    18.         ((Text)(buttonRT.GetComponentsInChildren(typeof(Text), true)[0])).text = label;
    19.       }
    20.  
    21.     AddRect(buttonRT, targetCanvas);
    22.     return buttonRT;
    23.   }
    24.  
    25.   public RectTransform AddLabel(string label, int targetCanvas = 0)
    26.   {
    27.     RectTransform rt = GameObject.Instantiate(labelPrefab).GetComponent<RectTransform>();
    28.     rt.GetComponent<Text>().text = label;
    29.     AddRect(rt, targetCanvas);
    30.     return rt;
    31.   }
    I would very much appreciate if someone could suggest a solution to this error :)