How to get the GameObject parameter linked to a OnClick event Button

Hi,

I’ve got a GUI Panel with each button linked to a different level (I know, it’s very innovative…).

I’d like to find how I could get via script the gameObject as shown here :

My wish is that the script would return “level01”.

I’ve tried several things but I couldn’t find anything closer than “GameManager” with this :

    void GarnirPanelLevel(){  
        Transform PL = GameObject.Find("PLevel").transform;
        foreach (Transform child in PL) {
            Debug.Log (child.gameObject.GetComponent<Button> ().onClick.GetPersistentTarget (0).name);
        }
    }

Any idea to get the “level01” ?

thank you,
all the best,
L.

the “PersistentTarget” is the slot in the inspector to the left of the one you’ve highlighted, the gameobject holding the component to be run… the slot you’ve highlighted is the parameter of the function being called on that target.

I suspect you need to look at: http://docs.unity3d.com/ScriptReference/Events.UnityEventBase.GetValidMethodInfo.html

not tried it though (only thing in the onclick i can see which talks about arguements/parameters :eyes:).

Thank you for your response.
Yes, the thing I need is the parameter of the function being called on the target, so I’ve tried the following thing :

...
            MethodInfo MI = UnityEventBase.GetValidMethodInfo (
                               child.gameObject.GetComponent<Button> ().onClick.GetPersistentTarget (0),
                               child.gameObject.GetComponent<Button> ().onClick.GetPersistentMethodName (0),
                new System.Type[]{ typeof(GameObject)} );

            Debug.Log (MI );
....

and here’s the console’s log :

Void AfficheLevel(UnityEngine.GameObject)
UnityEngine.Debug:Log(Object)
Void AfficheLevel(UnityEngine.GameObject)
UnityEngine.Debug:Log(Object)
Void AfficheLevel(UnityEngine.GameObject)
UnityEngine.Debug:Log(Object)
Void AfficheLevel(UnityEngine.GameObject)
UnityEngine.Debug:Log(Object)

So, how to know the value of this GameObject ( so, same problem…).
Don’t know how to figure it out.

Did you ever find a solution to the problem?

I’m doing an editor script and need to copy OnClick events from one button to another, but simply cant get the argument value :frowning: It’s all I need to get this to work.

Hope you found a solution and are willing to share it…

Hi,

I didn’t found any solution for this. I’ve changed the way to proced. It’s not very clean, but it works (see the menu in my game there : https://play.google.com/store/apps/details?id=com.Mazeballoid.Android&hl=fr )

Bump…

sputnikbar, I’d like to see your not-clean way to do this but the link you provided doesn’t seem to work for me.

Also, anyone else ever figure this one out? I’ve been looking for a while but no one seems to know it.

Thanks.

I’ve been looking for a solution to this same problem, to no avail :frowning: