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.

Prefabifying Button

Discussion in 'UGUI & TextMesh Pro' started by HappyLDE, Aug 21, 2014.

  1. HappyLDE

    HappyLDE

    Joined:
    Apr 16, 2014
    Posts:
    56
    Hi, can we prefab a button so that i don't change the text style and everything every time i create a button?

    Right now if i prefab a button, then create another button from that prefab it won't show in the scene.
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,165
    Are you putting the button on a Canvas?
     
  3. Josh-Naylor

    Josh-Naylor

    Administrator

    Joined:
    Jul 1, 2014
    Posts:
    216
  4. HappyLDE

    HappyLDE

    Joined:
    Apr 16, 2014
    Posts:
    56
    Thanks that works!

    Edit: And it's really awesome!
     
  5. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    545
    I'm currently trying the same thing, but mine are not showing up, as if not added to a Canvas. I simply Instantiate() the prefab, and then set its transform's parent to my Canvas'. What am I missing?
     
  6. asotelo94

    asotelo94

    Joined:
    Jan 26, 2013
    Posts:
    14
    How do you set the parent? because aparently panels don't have the regular transform.
     
  7. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    545
    Ooh, good point! I used "btn.transform.parent" though, and appearantly btn.transform automagically refers to the object's RectTransform. =) It's also in the correct place in the hierarchy; right besides its already-existing brothers and sisters.
     
    asotelo94 likes this.