• 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 mdgianino · Jul 05, 2015 at 09:23 PM · instantiatespriteprefabs

Spawning letter tiles evenly across screen

I have been watching the various Unity 2D tutorials available on Lynda as well as on the Unity website and I am trying to create a test game that simply has a grid of letters that are evenly distributed on the screen (think of a word search).

I have my actual letter tiles that were made in Illustrator (128x128 pixels) that I have imported into the project. I also have a Letter prefab that has a public Sprite property which is going to be set to a random letter in the alphabet (basically it loads the letter tile by selecting a random letter, and then loading "Letter_X.png" where X is the letter it selected).

This is all fine and works great when I manually drag the Letter prefabs onto the screen. My issue is that I am trying to get the game to spawn in a grid (of any size) of letters onto the screen and have them all fit nicely.

I have a general idea of what I think I need to do. I know I need to do the following:

If my grid is 10x10

  • Divide the screen width by the number of horizontal tiles in the grid (10). This will give me the size of each "tile"

  • Use the result of the above calculation to scale the size of the sprite accordingly.

  • Loop through each position, instantiating a Letter prefab at the current "grid position".

I am currently stuck on the third step. If my original sprite is 128x128 and my Pixels to Units is also set to 128, how would I then convert a location on the screen (which is not in units) to a position in the scene that is at the exact same spot. Further more, how would I make sure that my camera can always show all of the tiles on the screen without having any bleed outside of the edges of the screen?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Instantiate Reference Problem 1 Answer

Setting parent of instantiated sprite 2 Answers

Prefabs wont instantiate using a for loop? 1 Answer

How can I instantiate multiple objects with a loop and have them be different 1 Answer

Problems assigning sprite's images 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