Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 PlaguedShadow · Feb 04, 2015 at 08:54 PM · ui

[4.6] How do I make a UI object the same size as another UI object?

In my project I'm making a pause screen with the new UI system. I have an icon that will move around the screen, but I don't know how to get my icon to size correctly.

As shown in this image: http://imgur.com/2Z7r8Eb I need rectangle A to take on the dimensions of rectangle B so that it will completely overlap it.

How would I do this?

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

1 Reply

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

Answer by Mmmpies · Feb 04, 2015 at 09:45 PM

Hmmm, getting late (yet again) where I am but I think I can answer even if sleepy!

Set the anchors to the center of the parent for both objects, then drag the panels onto the public slots of this script:

 using UnityEngine;
 using System.Collections;
 
 public class MatchSize : MonoBehaviour {
 
     public RectTransform RTB;   // the one you want to resize
     public RectTransform RTA;   // the one you want to copy the size of
 
     // Use this for initialization
     void Start () {
 
         RTB.sizeDelta = new Vector2(RTA.rect.width, RTA.rect.height);
         RTB.localPosition = RTA.localPosition;
     }
 }

Sorry if rubbish, it's late!

Comment
Add comment · Show 4 · 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 PlaguedShadow · Feb 05, 2015 at 01:54 AM 0
Share

I seem to be having some problems with it. It doesn't scale properly still. This is what is happening:http://imgur.com/YJ2214r

I have my moving UI set to it's own variable and I have a variable set up for my objects. I have the anchor set to the center of the object and the borders around it as shown in this image: http://imgur.com/y$$anonymous$$RTaz3

Any idea why it isn't properly overlaying?

avatar image Mmmpies · Feb 05, 2015 at 10:42 AM 0
Share

Sorry night time fell. In that image you got the anchors set to the corners of the object. $$anonymous$$aybe we need another approach if you absolutely need it that way.

In my test both objects had the same parent object and the anchors in the center of the parent panel. That way it picks up the right settings.

I'll see if I can another way of doing it.

EDIT

In fact only the panel that moves needs to have it's anchors set to the center of the parent panel for both objects, is that workable for you?

avatar image PlaguedShadow · Feb 05, 2015 at 04:13 PM 0
Share

I moved the anchor points on my moving UI to the center of the object and that got it to work. Thank you very much for your help!

The only issue now is it stretches on the sides: http://imgur.com/v8$$anonymous$$2hNV

Any suggestions for fixing that?

avatar image Mmmpies · Feb 05, 2015 at 04:25 PM 0
Share

First, you can post images directly on here and it's pretty fast. See the button to the right of the paperclip. Just saves time jumping backwards and forwards between web pages.

As for the other issue that Vector2 is totally O$$anonymous$$ for manipulation. It's just 2 floats so just try (RTA.rect.width - 1f, RTA.rect.height) but test it at different resolution and aspect ratios (if res/aspect changes are likely for your platform).

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

20 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

Related Questions

Beta UI 4.6 - Red Cross on runtime objects 1 Answer

How to create an Alert Box in 4.6 UI? 3 Answers

How to change animation curve scripting? 0 Answers

Changing the Canvas RenderCamera by C# script ? 0 Answers

How to add callback for button press to a private function (New UI)? 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