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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Prefab with button doesn't work?

Discussion in 'UGUI & TextMesh Pro' started by merlock18, May 7, 2015.

  1. merlock18

    merlock18

    Joined:
    Dec 30, 2013
    Posts:
    28
    I have researched the problem with no answer.
    I am making a prefab that has a button. That button is set to call a func (public void ButtonPressed())
    It returns void and has no parameters. Why am I unable to click it when ran? Anyone know? Its simply supposed to move some other buttons around. I have a Debug.Log being called when the func is called and it's def not showing.
     
  2. DrowningFish

    DrowningFish

    Joined:
    May 6, 2015
    Posts:
    12
    Besure you're putting the button into a canvas.
     
  3. merlock18

    merlock18

    Joined:
    Dec 30, 2013
    Posts:
    28
    And it needs to be a part of a canvas to display at all. Making it a child of the main (only) canvas still makes it non-functional as far as I can tell. I am looking for a guide on generating buttons live and am finding nothing.

    And Button has a RectTrans but I have to access it with the GetComponent for some reason?

    So right now if I manually put the button as a child of the Canvas during run time it appears to work a bit so far. Thanks. I'm now off to figure out how to make it a child object upon Instantiation or just after...
     
    Last edited: May 7, 2015