I'm creating a tower defence game and I've been struggling on one of the core parts of the game. What I'm trying to do is create a plane that the user can clink on and build a tower at that location. Although I've searched for a while I could not find an tutorials or useful code on this subject.
The theory is simple. I started with making a script that creates small cubes to shape the platform the game will be played on.
public Transform PlatPrefab;
public Vector3 Size;
public int platX, platY, playZ;
// Use this for initialization
void Start () {
MakeGrid();
}
// Update is called once per frame
void MakeGrid(){
for (int x = 0; x < Size.x; x++) {
for (int z = 0; z< Size.z; z++) {
Instantiate(PlatPrefab, new Vector3(x+platX,platY,z+playZ), Quaternion.identity);
}
}
}
This is the part I'm stuck on, how do I develop a system that gets the coordinates of the single cube clicked on? I've worked with Raycast Hit and I'm only comfortable with it by simply using tags and if the mouse clicks on an object with the tag then do something. However I can't wrap my head around how I'm supposed to do this with Grids. Won't they need to be labeled for my to pick one individually?