Hi, I am newbie in programming and I am making a tower defense game 2d. My problem is I want to make a restriction to place a tower only, if the mother tower is in place or within its range. I’m sorry if my explanation is a bit confusing. For example, you can oly place a certain tower within the range of the mother tower and only if that mother tower is placed. I don’t exctly know if I have to create a function for this or create a range game object for the placement attached to the mother tower. Any help and tips would be appreciated, thank you.
Generally this is handled by having a method that is called when the piece is dropped that validates, “Hey, can this piece live here?” You can stack as many conditions as you want there: am I on another piece, am I even on the game board, is there a mother tower, am I close enough to the mother tower, etc.
The simplest fail would simply destroy the new tower and refund the player.
A better fail would report a reason for why it was destroyed and refunded, like (“Cannot place on a roadway!”)
And even more nuanced fail would actually tint the tower real time, either green or red, according to a per-frame check of place-ability, giving the player fine-grained feedback if what they want to do can be done.
Start with #1. It’s a good engineering lift to warm up with, and there are probably 200 or more tower defense tutorials out there for Unity, including fully functional example projects in the Unity Asset Store.