Author Topic: Dynamic button  (Read 9262 times)

NJ_kung

  • Guest
Dynamic button
« on: July 27, 2012, 06:48:07 AM »
Hello I am new-be of NGUI

I try to create dynamic button.

this is my code

-------------------------------------------

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [AddComponentMenu("NGUI/Examples/Test Dynamic Button")]
  5. public class TestDynamicButton : MonoBehaviour {
  6.         public GameObject btn1;//<<<my prefab button from default button
  7.         // Use this for initialization
  8.         void Start ()
  9.         {
  10.                 for (int i = 0; i < 20; i++)
  11.         {
  12.                         GameObject parent = GameObject.Find("UIGrid");//<<<< my UIPanel > UIGrid with Scroll Bar
  13.                         GameObject child = NGUITools.AddChild(parent,btn1);
  14.                         //GameObject button = child.GetComponentInChildren();
  15.                         child.transform.localPosition = new Vector3( 0+i*250 , 0 );//it is horizontal
  16.         }      
  17.                
  18.                 GameObject.Find("Panel-ButtonList").GetComponent<UIDraggablePanel>().ResetPosition(); //I see you say after add mush reset
  19.                
  20.         }
  21.        
  22.         // Update is called once per frame
  23.         void Update () {
  24.        
  25.         }
  26. }

-------------------------------------------------------------------------

After run It was create and can slide by Scroll Bar 

But It don't active when OnHover or OnPress  :o( It seem like texture not button )

Can you help me Thx. ;D

PhilipC

  • Guest
Re: Dynamic button
« Reply #1 on: July 27, 2012, 09:58:05 AM »
It seems like you prefab might be incorrect. Does it have a collider on it? Does it respond if you drag it into the scene manually?
« Last Edit: July 27, 2012, 10:17:29 AM by PhilipC »

NJ_kung

  • Guest
Re: Dynamic button
« Reply #2 on: July 28, 2012, 12:43:41 AM »
It work if I drag it into the scene manually.

NJ_kung

  • Guest
Re: Dynamic button
« Reply #3 on: July 28, 2012, 02:25:52 AM »
Ok now I can fix it  :)

I change hierarchy from Panel-ButtonList>UIGrid>Many button to  Panel-ButtonList>Many button now it work.

Thx for try to help me.