Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by FeeeshMeister · Dec 02, 2016 at 10:50 PM · uirecttransformrectdialogue

Problem with using Rect.set(), it does nothing.

When using Rect.set(), the rect does not change. I don't know how else to better explain it. Here is the code, with unimportant parts removed.

    RectTransform DialogueBoxRect = new RectTransform();
 
     void Awake()
     {
         Player.DialogueBox = GameObject.Find("DialogueBox");
 
         if(Screen.width < 1280)
         {
             DialogueBoxRect.rect.Set(0, 14, Screen.width - 20, 300); // Dialogueboxrect HAS already been defined and set
         }
     }

It returns no errors, but it does absolutely nothing. It should be changing the dialogue box's size to less than the screen, so that it can played in the gameview and be read, but it is still too big. Any help is appreciated, thanks in advance.

Comment
Add comment
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

2 Replies

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

Answer by hexagonius · Dec 02, 2016 at 11:01 PM

the problem is you're changing the rect of DialogueBoxRect, which you are creating though the constructor which is not allowed and won't do anything because this way it's not even a part of a gameobject. I guess you should instead be doing something like

 Player.DialogueBox.GetComponent<RectTransform>().rect.Set(...
Comment
Add comment · Show 2 · 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 FeeeshMeister · Dec 02, 2016 at 11:09 PM 0
Share

@hexagonius , I feel stupid now for not seeing that but it still is not working. This is what I am using now.

     private void Start()
     {
         if(Screen.width < 1280)
         {
             Player.DialogueBox.GetComponent<RectTransform>().rect.Set(0, 14, Screen.width - 20, 300);
         }
     }


Do you have any idea what could be wrong?

avatar image hexagonius FeeeshMeister · Dec 03, 2016 at 07:27 AM 0
Share

well, since I don't know if "DialogueBox" is even the right RectTransform, I don't know. But I have a clue. You're setting the rect once via code, but the RectTransform will be updated with every change made in any UI Element under its canvases hierarchy. I haven't used my brain really, so here is a better Idea altogether:
You can achieve the same effect without coding, which in this case is cleaner. Select the GameObject with the RectTransform. click the mill-like rectangle in the upper left that has "middle" and "center" written to it. It should show the anchor presets. Choose the bottom right (blue arrows). What this does is stretch the whole Rect fullscreen no matter the window size. The position and size informations to it's right should now read top left bottom and right. This is where you put your indentations you tried setting in your code. From now on, the actual Rect will keep its distance from the borders forever.

avatar image
0

Answer by logicandchaos · Feb 01, 2021 at 04:15 AM

try rt.sizeDelta = new Vector2(100, 100);

Comment
Add comment · 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

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

108 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

Related Questions

Place GameObject's rect 0 Answers

Convert RectTransform.rect to Rect world 3 Answers

Proper way to wait until dynamically added children of a layout group are rendered 0 Answers

How can I position a rect transform inside another via code? 0 Answers

Rect Transform limits vs position and size 1 Answer


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