Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Add Listener Problem

Discussion in 'UGUI & TextMesh Pro' started by XKnightmare, Sep 14, 2014.

  1. XKnightmare

    XKnightmare

    Joined:
    Sep 1, 2014
    Posts:
    5
    Hi Everyone,

    I'm having a issue when trying to add a listener through C#. I do have the following,

    using UnityEngine.UI;
    using UnityEngine.Events;
    using UnityEngine.EventSystems;

    However, when I do something like,

    button.onClick.AddListener(action);

    I get a error saying that there is no definition for onClick but I do have many other functions from 4.6 there. I have even downloaded a tutorial/example of someone else's 4.6 but I still get the same errors. I'm pulling my hair out here as I can't figure out why I can't figure out why the definition isn't there. All I'm trying to do is dynamically add a listener through script in the new 4.6 yet every answer to this question requires this method just about. Sure, I can do this through the editor visually, but I'm looking for a runtime method. Am I just missing something here?
     
  2. XKnightmare

    XKnightmare

    Joined:
    Sep 1, 2014
    Posts:
    5
    Well my errors came from having a conflict Button class from some random Asset from the Asset store. I knew everything was correct and it worked like a charm after deleting it.