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 Obsdark · Jul 31, 2017 at 07:26 PM · gameobjectprefabrenderingsizeresize

How to make sure two Tiles not overlap each other? (Unity3d C#)

I'm trying to make a Grid who will be easily convertible between 2D and 3D and i'm having a problem with overlapping prefabs in the case of the 3D generation.

The thing is, the DataObjects (Tiles) actualy have inside them the prefab of the thing who must be in that tile, but the prefab is bigger than the Tile.

Here is an example of what i mean

As you can see in the image, i have 3 Tiles selected, Each Tile have a prefab and all of them have the same kind of prefab, they are in the scene highlighted by the orange borders right now in the image.

Then you could imagine than, if the prefabs are equal between the 3 of them they should all have th same size, and that's exactly the case (i.e. in fact they have the same size) but the thing is they are overlaping each other, have that in consideration when looking at the image.

So the question will be...

How to make sure two Tiles not overlap each other?

based on a suggestion on working not with scale but pixels with units, i don't know exactly how to do that, but searching on google make me try this, which actualy doesn't work:

 tile.tile_GO.GetComponent<Renderer>().bounds.size = thisPrefab.GetComponent<Renderer>().bounds.size;

It doesn't work because "bounds" is read only.

Do you know a work around to solve this?, or is another way to achieve what i'm looking for?

Feel free to ask, comment, request for clarification or even correct my grammar, all would be welcome if it is respectfull, specialy if it helps to find and answer.

The idea is stop the overlapping, if you know a way to make one next to the other one, or even leave a gap between them in runtime, it will be also consider a valid answer.

Thanks in advance.

PS: i'm using unity 2017.1.0f3, scripting in C#.

apicturebiggerthan1000words.png (170.4 kB)
Comment
Add comment · Show 1
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 Obsdark · Aug 01, 2017 at 12:34 AM 0
Share

The idea is stop the overlapping, if you know a way to make one next to the other one, or even leave a gap between them in runtime, it will be also consider a valid answer

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by bgprocks · Jul 31, 2017 at 08:10 PM

temporarily unparent them, then resize the to match each other, then reparent them.

Comment
Add comment · Show 2 · 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 Obsdark · Jul 31, 2017 at 11:19 PM 0
Share

Doesn't work, i already write in the question than the problem is because bouds is READ ONLY, hence, i can't modify it, it doesn't matter if it is parented or not, thanks for the try anyway.

avatar image bgprocks · Aug 01, 2017 at 01:22 AM 0
Share

no prob, missed that part.

avatar image
0

Answer by x4637x · Aug 01, 2017 at 02:59 AM

Have you try something like this ?

 float x = tile.tile_GO.GetComponent<Renderer>().bounds.size/2;
 thisPrefab.transform.position = thisPrefab.transform.position + new Vector3(x, 0, 0);

Or do you want them to keep current position?

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

102 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

Related Questions

How can I determine an object of prefab's size (for positioning when instantiating them) 2 Answers

Not a question - just some performance metrics for rendering from Unity scripts 0 Answers

Spawn Prefabs 1 Answer

Creating an array of prefabs? 4 Answers

Replacing empty gameobjects with prefabs 3 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