Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: FOX_ITA on January 27, 2014, 03:27:09 PM

Title: UIGrid, how to get the index from a child
Post by: FOX_ITA on January 27, 2014, 03:27:09 PM
Hello there,

i'm pretty new to NGUI and i'm using it a lot.
But i can't figure out hot to determinate the index of a child clicked on the UIGrid.

I got a UIScrollView with attached an UIGrid with as a children different UIButtons.

How can i get the index or position of pressed button in the grid?

for example if i click on the first one i can see that is pressed the item 0 into the UIGrid.

Many thanks,

cheers!
Title: Re: UIGrid, how to get the index from a child
Post by: Nicki on January 27, 2014, 04:35:31 PM
  1. //assuming this is on the child
  2. UIGrid gridReference;
  3.  
  4. void OnClick()
  5. {
  6. int xPos = transform.localPosition.x;
  7. int index = (int) xPos / gridReference.cellWidth; //or cellheight
  8. }
Title: Re: UIGrid, how to get the index from a child
Post by: FOX_ITA on January 28, 2014, 07:50:51 AM
Thanks a lot,

i'm gonna test it right now!