zyonneo
zyonneo

Reputation: 1389

How to set the parent of GUI Button?

I have a GUI button initialised in OnGUI method.I have a panel which need to act as a parent for this GUI button.Currently it is displaying on the corner of the screen.

public Transform panelparent;
private GUIContent button_tex_con;

if (GUILayout.Button (button_tex_con, GUILayout.Width (100), GUILayout.Height (100))) 
        {
            Debug.Log ("Clicked");


        }

Upvotes: 0

Views: 170

Answers (1)

dsdel
dsdel

Reputation: 1062

Currently you are using the Transform class, however in WPF itself the Transform is no Framework/UIElement.

The transform class itself does derive from:

public abstract class Transform : GeneralTransform, IResource

If you want to have a Panel, use the following code:

// change canvas to the panel you want to initiate (eg. Grid / Canvas)
Panel panelParent = new Canvas();
Button button = new Button();
// set button to be child of panelParent
panelParent.Children.Add(button);

You can apply transformation to the Panel like this (example):

panelParent.RenderTransform = new MatrixTransform();
....

Transforms overview at msdn showing examples in xaml.

Upvotes: 1

Related Questions