Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
3
Question by ledisnomad · Apr 01, 2016 at 03:10 PM · scripting problemuipanel

Move UI panel on and off screen, scripted without animation

I have a menu on the left side of my screen that is currently showing. It is a Canvas with a Panel object, a Text object, and some Button objects. I would like the Panel and all its Buttons to be off screen when the game starts. A portion of the Panel and the Text, which is vertical and says "Menu", will be showing. When the player clicks the "Menu", I would like the panel to move onto the screen, showing all the buttons. Another click on the "Menu" text would move the panel and the buttons off screen again.

I have an Event Trigger on Pointer Click set on the "Menu" text. I have a script called "ToggleMenuUI" as a component on the Panel. The Panel is the Object in the "Menu" text Event Trigger using a public function called Toggle() in the script. What am I missing to make this setup work?

UPDATED: Figured it out! I had to use the anchoredPosition property rather than the position property.

Here is the (working!) script, kept up for helping others: using UnityEngine; using UnityEngine.UI; using System.Collections;

public class ToggleMenuUI : MonoBehaviour {

 private RectTransform rt;
 private Vector2 open;
 private Vector2 closed;
 private bool IsOpen;

 void Start () {

     rt = GetComponent<RectTransform>();
     open = new Vector2(-5.0f, -5.0f);
     closed = new Vector2(-82.0f, -5.0f);
     IsOpen = false;
 }

 public void Toggle () {

     if (IsOpen)
     {
         rt.anchoredPosition = closed;
         IsOpen = false;
     }
     else
     {
         rt.anchoredPosition = open;
         IsOpen = true;
     }
     
 }

}

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TozerAuthor · Nov 04, 2016 at 12:01 PM 0
Share

Hello,

I wish to say thank you, @ledisnomad. This piece of information has helped with my game menu's.

avatar image Michael_Starmik · Aug 17, 2020 at 07:54 AM 0
Share

Hello, I was looking for answer to this for some time and yours was the first I actually made some sense from. :) Thank you!

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

72 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Deleting random objects in started project 0 Answers

Trying to make an object appear in a position, but only if that position isn't occupied. 0 Answers

Canvas Structure for Different UI Panels 0 Answers

How do I keep two UI text unity3d on the scene 2 Answers

How do i change a color of an individual alphabet of a UI.Text 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges