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 Matthew_Armocida · Nov 13, 2015 at 01:47 PM · unity5canvasboundsrecttransform

Trying to get the top of a Canvas Object.

Hello, I'm currently trying to get the top of a canvas object using Unity in 2D mode. The transform positions give me the center of object but I would like to get the top bound.


The reason is that I am currently setting up a start menu screen which displays the games title on a background (which I will later have animated) along with some particle effects going on (lightning striking and rain, ect). I am currently trying to get the lightning to start at the top of the the canvas.


  1. The Canvas' Render mode is set up as Screen Space - Camera because I wanted to ensure that it resizes for different aspects and I wanted to be able to set its order in a sorting layer such that I could draw the lightning over it and its child components.

  2. Currently it is positioned at a Y of 181 under its transform.

  3. The height listed is 557.

  4. However the actual top border of the canvas rests at something around 221.64.

  5. Rotation is 0, and scale is 0.16502 for X, Y, and Z axises.

I has originally assumed that the difference between the center point of the rectangle and the upper bound would be half its height so I did the following (I was planning to change the values under Random.Range to follow suit if I could get this to work):

         startPos = new Vector2(Random.Range(300, 500), ((CanvasUsed.GetComponent<RectTransform>().rect.height / 2) +
             CanvasUsed.GetComponent<RectTransform>().transform.position.y));

However as I'm sure you'll notice the difference between 221~ and 181 (40) is not half of 557 (278~). Now I'm looking for alternatives to figure out where to get the position of the top of the canvas. I was considering just adding a blank object as a child of the canvas and positioning it via anchor where I want, then using the position of that, however, it feels a little bit weird for a workaround and I'm sure this kind of thing will come up again in the future. Thank you for your time.

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Problem moving a panel UI 0 Answers

Text Colour Gradually Change Animation 0 Answers

Change Text Scale on a Canvas Child from a script. 1 Answer

Set Native Size in UI 1 Answer

Good way to scale 3D GameObjects in a Canvas (Screen Space - Camera)? 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