Author Topic: Button select screen  (Read 7104 times)

Rick74

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Button select screen
« on: January 04, 2014, 06:53:19 PM »
Hey guys.

I'm trying to do a button select screen much like plants versus zombies.



I first tried instantiating a prefab NGUI button into the screen through a button message script, but it comes in extremely large and not within the NGUI hierarchy.  Is their an example that I can look at that does this?  Or a method of using NGUI interaction script templates? 

I was leaning towards drag and drop example, however I just need something more simple.  You press one button, and it shows up in your button select area.  No dragging, no dropping. 
Thanks
« Last Edit: January 04, 2014, 08:19:30 PM by Rick74 »

John.Bergman

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 30
    • View Profile
Re: Button select screen
« Reply #1 on: January 05, 2014, 01:37:20 AM »


Add an onClick() eventhandler to the button(s);  In the eventhandle,  since you have the instance of the control (UIButton.current), you can remove it from the bottom one... or if you want, you can probably reparent it to the upper panel. 

If you want to create a new button, you could add a script that only has a public variable that is populated some something like the name of the object, and use that to determine what to create in the upper area (and/or save it as settings)

Rick74

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Button select screen
« Reply #2 on: January 05, 2014, 12:16:19 PM »
Hey thanks for the response!  The end result would just have a new button show up in the upper panel. 

I've thought about this allot of the past day or so, and I've come up with two options.

- Instantiate a new button, and figure out how to parent the button clone back into the panel Hierachy ( i don't know how to do that yet, but I'm sure it can be done)

- have all my buttons hanging out offscreen and simply use a "transform position "tween" NGUI script to pop it into place.

- Instantiating a new button prefab, and I notice the scale is HUGE.  (which makes me think I'm probably doing this wrong or missing a key step here.
- having all the buttons hang out off screen means I load them all every level.  I'm probably going to favor this idea, as there are no hierarchy changes, just a move.  If I keep my duration low enough... ("say .01" )  Hopefully the player will not see the translation.  Or I can forget using the NGUI tweener and just create my own.

I was just hoping there was already a preset script that does this or an example out there which makes this a tad easier.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Button select screen
« Reply #3 on: January 05, 2014, 05:12:59 PM »
You need to use NGUITools.AddChild(parent, prefab) instead of Instantiate().

Rick74

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Button select screen
« Reply #4 on: January 05, 2014, 06:57:52 PM »
Thanks for the heads up!  I'll give it a shot!