GetComponent<UICenterOnChild>().onCenter = YourCallback;
You really should just google "c# delegates".
I'll take another, deeper look at delegates but I asked here because I thought if I got the answer I'd understand the missing piece.
Doesn't onCenter trigger when the scripts starts centering on a new child object in the grid?
I also want to find out which specific child object it is.
EDIT:
Ok, I found the centeredObject but now NGUI changes the name of my objects to 0,1,2,3 and when you go in the other direction -1,-2,-3 etc. It would be ok if this was consistent, but the name changing happens at random, should it be like that?
On another note, when I try to compare centeredObject with my gameobjects it works if I use an IF statement but doesn't work when I use switch, like so:
Let's say I create an array of gameobjects to plug in these child objects so I can refer to them from the script. Then I'd like to write the Switch function like:
public GameObject
[] childArray
= new GameObject
[2]; GameObject temp = UICenterOnChild.centeredObject;
switch(temp)
{
case childArray [0]:
//do something
break
case childArray [1]:
//do something
break
default:
break;
}
Unity throws an error though saying "A switch expression of type 'Unity GameObject' cannot be converted to an integral type, bool, char, string, enum or nullable type"
I know this latter problem is not really NGUI related but does anyone happen to have an idea why switch statement can't process the gameObject?
Thanks