Currently I’m developing a tower defence game and the game is in the latter stages of development. I have a grid with many tiles (8 by 5) and towers can be placed on these tiles by a raycast. What happens is that the tiles contain a variable called isValid and at the start of the game, every one is set to true but when a tower is placed on one, it’s value changes to false.
During the course of the game, enemies come along and attack the towers and perhaps destroying, what I’m looking for is a piece of code to tell the game to free up that tile again and make isValid equal to true so that another tower may be placed there.
One thing to note though is that all the tiles are just called Tile, there isn’t anyway of separating them without a raycast that I know of.
Can anyone help me with this situation, I look forward to hearing replies
ummm isVaild = true ? When you determine which tile the bad guy is attacking then you have a reference for it and you can just set it to true once destroyed.
Yes, but something has to come before. Towers are objects, currently just cylinders, squares etc… until I implement artwork. The enemies are also objects, these attack each other and not the tiles. The tiles are just the playing field, but once a tower is placed, it does not keep a reference of which tile it is on.
What I’m asking is that when a tower is destroyed, the tile should be freed up and be set to isValid=true but I don’t have a reference for a tile.
Any suggestions on how to fix this?
N.B. Calling all the tiles different names could work but would take to long to fix and completely make a mess of my raycast script which determines if a tile is clicked, if it’s free then creates a tower on it. I’m looking for another solution.
Wow, not holding all of the tiles in an array of some sort and updating the array when you place a tower, sounds messy.
Since you know when you’re going to destroy the tower, can’t you have the tower gameobject use your raycast, right before it blows up, setting isValid = false?