Author Topic: Popup NGUI Prefab after onClick from another object  (Read 8773 times)

E1iTe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Popup NGUI Prefab after onClick from another object
« on: August 15, 2012, 12:51:06 PM »
Greetings,
     I'm very new to Unity and NGUI but i'm starting to get a hold of everything. But i'm trying to make a NGUI prefab (a window and a few buttons) "pop up" when I click on a game object. For the script to show and hide the pop up I have:

   public GameObject prefab;
   private bool isVisible;
   // Use this for initialization
   void Start () {
   prefab.gameObject.SetActiveRecursively(true);
   }
   
   // Update is called once per frame
   void Update () {
   
   }
   public void toggleVisible() {
    if(!isVisible){
         prefab.gameObject.SetActiveRecursively(false);
         isVisible=false;}
      else{
         prefab.gameObject.SetActiveRecursively(true);
         isVisible=true;}
   }

I'm not sure how to create this prefab and place it on the screen under the correct place (UI Root 2D -> Camera -> Anchor -> Panel correct?). Again I apologize because I probably know this is a noob question!

Thanks,
Jason

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Popup NGUI Prefab after onClick from another object
« Reply #1 on: August 15, 2012, 12:54:20 PM »
Use NGUITools.AddChild() to create your prefab. This function has 2 parameters -- one of them is the prefab, and the other is the parent that you're adding this child to.

E1iTe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Popup NGUI Prefab after onClick from another object
« Reply #2 on: August 16, 2012, 10:23:49 PM »
I have been trying to figure this out all day... i'm trying to pop this prefab up when i click on another object in the main game controller script but still can't find enough documentation to make this happen, sorry.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Popup NGUI Prefab after onClick from another object
« Reply #3 on: August 17, 2012, 09:26:48 AM »
?

  1. public class CreateOnClick : MonoBehaviour
  2. {
  3.         public GameObject parent;
  4.         public GameObject myPrefab;
  5.  
  6.         void OnClick ()
  7.         {
  8.                 NGUITools.AddChild(parent, myPrefab);
  9.         }
  10. }