1

I want to create a Magic Jewelry clone (Tetris + match 3) using Unity for mobile. So far, I've used UI elements such as UIImage, which serves as an individual block. I created a script that will give out random colors for the box. I then parented three blocks to an empty game object named GameObjectParent.

For the movement, I created another script that subtracts the GameObjectParent's anchoredposition.y every second. In terms of collision, I created a transparent UI Image that will serve as ground triggers that will stop the GameObjectParent's movement once it's entered.

My problem now is the matching of the colored blocks, and more importantly, Instantiating the GameObjectParent. I tried using out

RectTransform gRect = theCanvas.GetComponent<RectTransform>();
     var groupH = Instantiate(GameObjectParent, new Vector3(0,0,0) , Quaternion.Euler(0,0,0));
     groupH.transform.parent = theCanvas.transform;
     groupH.transform.localScale = new Vector2(1, 1);

But it somewhat spawns out of place. I have a "startingblock" that is currently anchored on the canvas at (50, 810), which is where the spawned blocks should start. However, when I try this:

var groupH = Instantiate(GameObjectParent, new Vector2(80,810) , Quaternion.Euler(0,0,0));

The newly cloned and spawned GameObjectParent goes out of place (21392,8712398). I don't know what's happening. Even so, if I attach the Instantiate method on a keypress, it spawns two GameObjectParents at a time, the other being slightly tilted.

I also have no idea how to match the colors of the other blocks as well. I tried searching for similar game concepts like this for unity but to no avail. There are also no tutorials/guides/pointers etc. so I really have to discover it on my own. Any thoughts about this guys? And are there any pointers, guides, or anything that you could give me?

Much appreciated!

MarredCheese
  • 17,541
  • 8
  • 92
  • 91
Dranreb
  • 313
  • 3
  • 11

1 Answers1

1

First, I wouldn't recommend using UI elements as game objects. We only use UI elements for, well, UI. Consider using sprites or quads instead. You can check Unity tutorials for making 2d games.

For matching, you can assign a code for each color. I usually use enums and bit masking.

Brian T.
  • 66
  • 4