0

I am making a puzzle using drag & drop in unity. The puzzle piece is like Tetris-piece, each puzzle piece is composed of a group of cubes. the puzzle piece needs to be dragged and then dropped into the slots of missing cubes of the structure(e.g. rectangle). The code is nicely done, but I am struggling in making objects.

Here's the screenshot of my sample game.

Heres the scenario

The problem is each structure is composed of a group of cubes. when I drag a single cube it perfectly goes to the slot where I dropped it and that slot will be occupied. But when I drop a piece which is composed of two cubes. it only occupies one slot,because, that piece, although has two cubes, is counted as one object, because it's stored in a parent object , another problem is the object's anchor is placed at the center so it will not fit each block because that anchor will be the one that will find the nearest slot where it will be dropped. So, My question is how do I make an object(parent) with many cubes(children) without it making as one? or without losing each objects positioning?

Critics
  • 59
  • 11
  • Welcome to StackOverflow. Nobody here is afraid of code, but without it we can't really do anything but provide moral support. If you want more help, you'll need to give more code. – leigero Sep 08 '16 at 19:22
  • Why can't you just have a collection of objects? Or a parent object which holds a collection of cubes? – leigero Sep 08 '16 at 19:24
  • I have tried to make a parent with a collection of cubes. but when i do that the cubes will be counted as one. so when i drop it to the structure it will only occupy one slot only in the front-end it looks like it occupies every slot but in the back end it really is not. And i have to check if all the slots are already occupied so the player can move to the next stage – Critics Sep 08 '16 at 19:38
  • Well I can't really help without seeing the drop logic. If it were me I'd drop a parent object, loop over its children and then place the child objects into the grid where they belong. But then I don't fully understand how your game works, nor do I have any idea what your drop logic or grid logic looks like. I failed out of psychic school so I'm not going to be much help. – leigero Sep 08 '16 at 19:46
  • I have attached a screenshot of my game. only its is a link type. please consider – Critics Sep 08 '16 at 19:55

1 Answers1

0

You can simply drag game objects over others in the hierarchy window to create children which can then be relatively positioned within the parent.

Perhaps look into Prefabs (https://unity3d.com/learn/tutorials/topics/interface-essentials/prefabs-concept-usage) they will allow you to group game objects and position them as a group, position each sub game item individually using a local position (relative to the parent) which is essentially the same functionality but are grouped outside of the hierarchy window and can be dropped into a scene as a group or instantiated through script

Scott Perham
  • 2,410
  • 1
  • 10
  • 20