As part of creating a turn based RPG combat game on Hex Grids, I have couple requirements.
The hexagons are individual game objects right on the scene editor.
Depending on movable, attackable, the grids need to be colored in different colors: green, red, yellow , etc.
The colored hexagons need to have a pulsing effect when showing.
The hexagons are initially invisible and only appears when it is colored and pulsing. I am looking for some tips on how to design the prefab. I don’t need to be provided entire script code and etc, I just need some ideas as to how to achieve this and I can figure out the implementation details by searching the net.
You can design the prefab as a simply a SpriteRenderer with a script to control it’s components and interface with it if necessary. The easiest way to get the pulsing effect is to have a secondary sprite child, which you can tint and scale up and down while the hexagon is enabled. An alternative is to use a 2D glow material.
The script should be able to hold or get all the data necessary for the hexagon to set itself up on start. ie. colors for states, references to components etc. Usually passive objects in the scene can be simple state machines. My preferred approach is to create an enum of states that it can be in, with a “currentState” variable of that enum type, or for more granularity you can use multiple booleans ie. “bool isAttackable” “bool isMovable” to use for state changes.
I would suggest making the hexagon a white sprite, and tinting it via the script.
You could use OnEnable and OnDisable in the script to control the on/off states.
Since you will have many of these in a grid, i would recommend avoiding the use of the Update function whenever possible, in favor of event-based or external function calls to tell a hex when to change state. That way you don’t have every single hex running code every frame.