Creating an Interactable Grid for Tactics Game (C#)

I’m making a tactics based RPG along the vein of Final Fantasy Tactics. The first thing I attempted was getting some code together that would create an interactive grid that would sit over the ground and make it easier to handle movement. I was new so I tried to understand someone else’s script instead of trying to figure out my own.

The script I found works, but it’s time to script my player movement phase and I don’t know how to display to the player how far they can move. I have a variable for it but I don’t know how to take that variable and change the color of just the squares which the player can reach. The code also doesn’t handle elevation at all. I can’t change the height of specific cubes. I think I need a new system. Perhaps if I set out the cubes manually and assigned each of them a value, I could then interact with them that way? Any and all advice would be immensely appreciated. Below is my script as it exists now:

In my manager script:

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class Manager : MonoBehaviour {
public GameObject TilePrefab;
public int mapSize = 11;
List <List> map = new List<List>();

// Use this for initialization
void Start () {
    generateMap ();   
}
   
// Update is called once per frame
void Update () {

}

void generateMap(){
    map = new List<List<Tile>> ();
    for (int i = 0; i < mapSize; i++) {    //i and j are the two values on the eventual vector2
        List <Tile> row = new List<Tile> ();
        for (int j = 0; j < mapSize; j++) {
            Tile tile = ((GameObject)Instantiate (TilePrefab, new Vector3 (i - Mathf.Floor (mapSize / 2), 0, -j + Mathf.Floor (mapSize / 2)), Quaternion.Euler (new Vector3 ()))).GetComponent<Tile> ();
            tile.gridPosition = new Vector2 (i, j);
            row.Add (tile);
        }
        map.Add (row);
    }
}

}




**In my Tile script:**

using UnityEngine;

using System.Collections;

public class Tile : MonoBehaviour {
   
    public Vector2 gridPosition = Vector2.zero;
    // Use this for initialization
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {
       
    }
    void OnMouseEnter(){
        transform.renderer.material.color = Color.blue;
        Debug.Log ("my position is (" + gridPosition.x + "," + gridPosition.y);
    }
    void OnMouseExit(){
        transform.renderer.material.color = Color.white;
    }
}

You’re doing about right with the tile script. You just need to add some methods there to flag it as “within movement range” and change its color just like in the OnMouseEnter.

As for manager, I don’t like List < List < Tile > >. You need something you can access by index like array or map if your coordinate is a struct.

So it could work like this: Player notifies Manager about his desire to move. Manager calculates all possible coordinates player can reach, iterates over them and notifies them that they belong to reachable area.

Pseudocode would be like

Manager:MoveArea(Player,ActionPoints)
{
    Tile reachcbleTiles[] = Reachcble(Player.Tile, ActionPoints); 
    foreach( Tile t in reachableTiles)
    {
        t.SetReachable(true);
    }
}