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 Yukiarashi · Nov 26, 2020 at 01:26 PM · canvaschildgriddetection

How to detect the border of a canvas grid and fill the slots of the grid with different shapes of blocks?

Hello, I need some help with my grid system. alt text

I created a grid system as an 2D-Array of GameObjects. Each of this GameObjects are Slots with a DropHandler Script. I also have a DragHandler Script to put dragged objects into the slot and let them snap into it. This works fine with a single object, which is the same size as the slot.

Now I want to drag different shapes into the grid (like Tetris blocks for example). These blocks are groups of the single object block. How do I define the border of the grid, so that no object can clip over it? This is the case for the object in the upper right corner of the grid shown in the picture.

I also want to detect which block of each group is in which slot of the grid, but when i take the group out of the grid it should stay as a group like before. In my current grid which is working with a single object block I added the block to the grid slot like shown in the picture. I don't know if that is also the right way for group blocks.

The detection of a full slot should not be that difficult, because I can access each slot of the grid from script through the array. But before that I need some help with this. I was testing several ways to do this the last days but with no success.

It should be working in the Canvas, because it is needed in the menu. Hope someone can help me with my problem.

square.png (29.2 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

2 Replies

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

Answer by Yukiarashi · Nov 27, 2020 at 12:34 PM

Solved my problem. Made a workaround with 2D Box Collider for every slot and dragged child of the box group with different tags. I also made a 2D Polygon Collider for the different shapes of the block groups. Then I used a 2D Edge Collider as border for the grid.

I don't know if this is good solution or not but it works fine for me now.

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
avatar image
0

Answer by jimmiewalker653 · Nov 26, 2020 at 04:25 PM

Double check your anchor positions. Also, make sure the canvas is set to "Scale with Screen". Double checking and fixing both of those should fix your issue. If it doesn't then make sure the scale is set to 1,1,1 for all UI gameObjects. If they're not, then reset the scale to 1,1,1 and then move and anchor in the points as needed.

Comment
Add comment · Show 1 · 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 Yukiarashi · Nov 26, 2020 at 05:34 PM 0
Share

Thank you for your answer, but this is not exactly my problem. The problem is, that I attached the DragHandler Script to the group parent of the block group and not to every single block because I want to move the entire group at once. When I drag the group to a slot only this slot will be full and not the other ones around it. I can't attach the DragHandler Script to every child because then I separate the group.

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

150 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 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

Adding a string to grid layout group 1 Answer

Making canvas a child of another gameObject 2 Answers

Questions about Grid Movement. 1 Answer

Making Selectable UI Grid objects 0 Answers

When I deleted an UI obj. in a cell, I want an empty cell. How can I do this? 0 Answers


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