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
1
Question by Mister-Kweh · Apr 13, 2017 at 03:12 PM · c#cameraguidynamic

Getting the Camera to Match the Size of the canvas with dynamically added UI elements

What I am trying to do is get the camera to show all of the UI elements being generated, even if that means they are resized or there is a black area to the left or right of main content. Basically just trying to generate a tilemap for testing purposes right now. And yes, the length and width in tiles of the map can change. How would I go about doing this without changing the UI elements' position in relation to each other? When I have the Canvas Scaler Scale mode Set to Constant Pixel Size, I get the look I want from the elements, but they are not within the camera viewport. If I change the Scale mode to Scale with Screen Size I still don't get all the elements in the viewport and now they are much smaller and more spread out in relation to each other. I'll attach some images of my canvas settings. Thanks in advance!

Oh and here is the code I am using to instantiate the tiles:

 for (int i = 0; i < width; i++)
 {
      for (int j = 0; j < height; j++)
      {
            GameObject.Instantiate(emptyTile, new Vector3(i * tileSize, j * tileSize), Quaternion.identity, alt textGameObject.FindObjectOfType<Canvas>().transform);
      }
 }
     

alt text

alt text

canvas-settings-with-desired-relationship-between.png (299.7 kB)
canvas-settings-without-desired-relationship.png (330.1 kB)
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
0

Answer by Bamboy · Jun 20, 2017 at 01:35 PM

I'm having a similar problem to this. I want to create a minimap where the small camera doing the rendering matches the size of a rect transform under the canvas so that I can have a clean border. Like the OP said, setting the canvas scaler mode to constant pixel size gets the result I want, but then my other UI isn't gonna scale correctly for different resolutions. Doing a seperate canvas doesn't exactly work either as the minimap cam is likely to overlap my other UI.

This seems like it should be easy to do, but I can't seem to figure out the math or whatever is required. Help would be appreciated.

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

How to adjust collision detection according to URP viewport rectangle change 0 Answers

How to adjust collision detection according to URP viewport rectangle change 0 Answers

Clamp To The Screen Edge 0 Answers

What to use for dynamic loading of assets instead of Resources.Load()? 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