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 /
avatar image
0
Question by ma22be61 · Aug 23, 2017 at 05:51 PM · uiui imagerecttransform

Cannot resize UI Panel

That's the code (it's pretty self-explanatory):

     bool showMenu;
     GameObject overLay; //this is the GameObject (the panel) with the RectTransform attached to it
 
     void Start()
     {
         showMenu = false;
         overLay = GameObject.Find ("Overlay");//That's the name of the panel
         overLay.SetActive (false); // I want to activate only when I click the button (this works)
     }
         
     void Update () {
         var getLeft = overLay.GetComponent<RectTransform> (); //getting the recttransform from the Panel
         if (showMenu == true) {
             
             overLay.SetActive (true); //activating the panel
             var transP = getLeft.sizeDelta; 
             transP = new Vector2 (0,0); //this part of the code is supposed to resize the Panel but it does absolutely nothing , no matter what value I put in
         } 
         else if (showMenu == false) {
             Debug.Log ("do stuff here");
         }
     }
 
     public void activateMenu(){ //Function that sets the showMenu to true once I click a button
         showMenu = true;
     }


What I'm trying to do here is get the panel gameobject and then get the panel recttransform. I use the recttransform to resize the panel but anything I try does nothing.

Comment
Add comment · Show 1
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 Positive7 · Aug 23, 2017 at 06:25 PM 1
Share

transP equals Vector2.zero and not the panel sizeDelta. You have to pass the value to getLeft.sizeDelta.

 getLeft.sizeDelta = transP;

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by tablekorner · Aug 23, 2017 at 06:26 PM

Setting transP to the new Vector2 won't affect the actual sizeDelta. transP isn't referencing the sizeDelta of the RectTransform, it's just storing the same value as it. Perhaps changing the if statement to this:

 if (showMenu == true)
 {
     overLay.SetActive(true); //activating the panel
     getLeft.sizeDelta = new Vector2(0, 0);
 }
Comment
Add comment · Show 6 · Share
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 ma22be61 · Aug 23, 2017 at 06:37 PM 0
Share

Ok , never$$anonymous$$d , this works. I am sorry to the user that commented before and told me that (I was setting it to 0 so nothing was changing).

Is there any way to make this slowly increase in size? I thought about something like this

 if (show$$anonymous$$enu == true)
  {
      overLay.SetActive(true); //activating the panel
      getLeft.sizeDelta = new Vector2(0+1, 0);
  }

This doesn't really work though. It only increases the size by 1 only once.

avatar image tablekorner ma22be61 · Aug 23, 2017 at 06:45 PM 0
Share

For sure you can. Just create a variable, float, int, whatever kind you want at the start. Set it to 0 or whatever starting value you want. Then increment it if show$$anonymous$$enu is true.

 bool show$$anonymous$$enu;
 GameObject overLay;
 float inc = 0; // or an int
 
 void Start ()
 {
     show$$anonymous$$enu = false;
     overLay = GameObject.Find("Overlay");
     overLay.SetActive(false);
 }
 
 void Update ()
 {
     var getLeft = overLay.GetComponent<RectTransform>();
     if (show$$anonymous$$enu == true)
     {
         inc += 0.75F; //or inc++;
         overLay.SetActive(true);
         getLeft.sizeDelta = new Vector2(inc, inc);
     }
     else if (show$$anonymous$$enu == false)
     {
         Debug.Log("do stuff here");
     }
 }

Now you can also stop it from incrementing when it's at the size you want, if that's what you want to happen:

by changing

 if (show$$anonymous$$enu == true)

to

 if (show$$anonymous$$enu == true && inc <= 175) // Or whatever value in place of 175 you want.

And if you want to size it different height, and width, just use to increment variables.

avatar image ma22be61 tablekorner · Aug 23, 2017 at 07:00 PM 0
Share

Thanks , it works but there is one problem. I want that the starting size is 0 but it starts at full size and then increases (while I would like to start at 0 and then increase)

Show more comments

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

113 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 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

How to animate UI rect transform which works for all resolutions 1 Answer

How do I scale the Xmax value of a RectTransform 3 Answers

RectTransform returning incorrect rect bounds 0 Answers

Converting to "Rect Transform" permanently deleted part of my project 0 Answers

Resizing UI Image but with minimum width 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