Author Topic: [Grids 2D] Looking for function to set cell as highlighted  (Read 43 times)

copyleft

  • Newbie
  • *
  • Posts: 3
    • View Profile
[Grids 2D] Looking for function to set cell as highlighted
« on: January 10, 2021, 01:16:51 AM »
https://streamable.com/dgw04t

I'm working on moving this cursor and highlight across my Grids2D cells.

I am working if there's a way to use the same highlight effect, but on keyboard WASD/arrow movement. Something where I can set a cellIndex as highlighted, and clear the rest.

copyleft

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: [Grids 2D] Looking for function to set cell as highlighted
« Reply #1 on: January 10, 2021, 01:28:09 AM »
One other thing, can I control what sprite layer the grid should be drawn on?

Right now, it's drawing lines over portions of my map that aren't traversable. I thought it was rendering on the Default sprite layer, but even buildings I have set on a higher sprite layer still get drawn over.

You can see it at the foot of the castle in the video.

EDIT: It seems adjusting the camera size fixed it grid rendering. Question still stands though.
« Last Edit: January 10, 2021, 04:46:40 AM by copyleft »

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6521
    • View Profile
Re: [Grids 2D] Looking for function to set cell as highlighted
« Reply #2 on: January 11, 2021, 09:31:15 AM »
Hi,

Yes, download latest beta first.
Then, you should be able to use a code like this, which manually highlights any cell:

Code

GameObject currentlySelected;

private void Update() {
grid.highlightMode = HIGHLIGHT_MODE.None;
        if (Input.GetKeyDown(KeyCode.A)) {
if (currentlySelected != null) {
grid.HideHighlightedObject(currentlySelected);
}
int row = 5;
int column = 5;
int cellIndex = grid.CellGetIndex(row, column);
currentlySelected = grid.HighlightCellRegion(cellIndex, true);
            }
        }

When pressing "A", the above code will highlight a random cell. Of course modify it so it reacts to cursor keys and have into account