sliding puzzle game in unity2d

Hi guys,

First time posting here. I’m trying to implement a simple tile sliding game such as can be seen here - Tile game - Tile games - Tile puzzle - Tile puzzles - TilePuzzles.com

I see plenty of tutorials for making something similar but where you click the tile adjacent to the empty slot and it will swap places with it (like this type of thing - Tile moving puzzle game - YouTube). This is not what I want. I would like to be able to drag multiple tiles together much like would be possible in the real life version of the game. I would also like for the tiles to snap into (the closest) place when the mouse is released.

I have snapping and stuff implemented, really more looking for how to move multiple blocks together in a specific axis as a space becomes available.

Thanks in advance for any help offered!

BI

EDIT: updated post after advice in comment below

The likelihood of getting assistance is inversely proportionate to the length and complexity of the script you’re posting. :wink:

Also, whether this question is appropriate for UA is borderline at best. (Open-ended stuff belongs in scripting forum) But it’s written with care and intelligence, so I would have approved it too.

I didn’t try to follow your execution flow, but I gave it a once-over. I observe that you have solutions or partial solutions for parsing input, enforcing the snapping behavior, all that good stuff. Honestly, if it works, it doesn’t matter if it’s “embarrassingly terrible”. I’ve been at this for eight years and write at least some embarrassingly terrible code every day. It might get revised, it might come back to haunt me, but forward progress is perhaps the most important reinforcement for self motivation.

If you’re “only getting started” with C#, I wouldn’t get bogged down asking whether something is the best or wisest method. Necessarily, most of that understanding is earned through experience.

Would a seasoned coder approach this situation differently? Well, yeah. Would their solution be half as long, half as complex, and twice as easy to manage? Probably. The fact is though, this early in your learning career, that just doesn’t matter.

We / I could analyze your solution and tell you how I’d have done things differently, but your focus should be on building familiarity with coding, unity, and game design fundamentals. The tricks of the trade - brevity, readability, modularity - and confidence come as you go.

If you had / have more specific questions (what is A? is B superior to C? if D and E and F, how do I get G?), those are more prone to getting solid answers, and are more what UA is all about.

Best,