2
\$\begingroup\$

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

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 exactly how to do that, but searching on google make me try this, which actually 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? Is there another way to achieve what I'm looking for?

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#.

\$\endgroup\$
4
  • \$\begingroup\$ When dealing with spatial issues, a picture is often worth a thousand words. Show us your prefab, show us the tile it needs to fit in, and we can tell you how to scale them to make them line up. \$\endgroup\$ – DMGregory Jul 31 '17 at 19:36
  • \$\begingroup\$ Good idea, i'll upgrade the question acordingly, thanks ;) \$\endgroup\$ – user57129 Jul 31 '17 at 19:44
  • \$\begingroup\$ As someone who's not familiar with your game, it's not obvious to me in this image which orange box represents the current size of the object, and which box represents the size it "should" be after scaling. Can you try to explain this in more detail? Don't hesitate to include additional diagrams if it helps. Over-explaining is definitely better than leaving people guessing. \$\endgroup\$ – DMGregory Jul 31 '17 at 21:35
  • \$\begingroup\$ 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 \$\endgroup\$ – user57129 Aug 1 '17 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.