I am trying to create a sort of menu for a game. I have put my main content on one panel and the menu contents on another. The menu panel is kept to the side of the main panel. I want to place a button on the main panel which when clicked would position the menu panel on top of my main panel. A button on the menu panel would push it back to its original position. What would be the script for these buttons?
\$\begingroup\$
\$\endgroup\$
4
-
\$\begingroup\$ RectTransforms are still Transforms. How would you place two GameObjects in the same position normally? \$\endgroup\$– Draco18s no longer trusts SECommented May 9, 2017 at 16:14
-
\$\begingroup\$ by capturing the transform.position.x in a variable and then changing the value. \$\endgroup\$– Subhadeep SarkarCommented May 9, 2017 at 17:03
-
\$\begingroup\$ So, apply that to your UI elements. It's the same deal. If that doesn't work, you need to update your question as to why that doesn't work. \$\endgroup\$– Draco18s no longer trusts SECommented May 9, 2017 at 17:35
-
4\$\begingroup\$ Possible duplicate of How do I set the exact local position of a RectTransform? \$\endgroup\$– DMGregory ♦Commented May 9, 2017 at 19:34
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
This worked:
public GameObject leadersPanel;
public void ShowLeaders()
{
leadersPanel.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0f);
}
public void ShowMain()
{
leadersPanel.GetComponent<RectTransform>().anchoredPosition = new Vector2(-800, 0f);
}