aka
New Member
Posts: 5
|
Post by aka on Jun 11, 2018 17:39:30 GMT
I'm trying to crib the visual style of an old favorite, just for the satisfaction of it. The title is Shining Force, for anyone curious. Regardless: an element of the style I find very iconic is a flashing movement/range highlight on the tiles. This bit of code makes it look just right, when applied to a tile (my tiles have been textured as well):
public class Flasher : MonoBehaviour {
public bool flashOn = false;
public Color lerpedColor = Color.white;
void Update() {
if (flashOn == true){
lerpedColor = Color.Lerp(Color.white, Color.black, Mathf.PingPong(Time.time, 0.5f));
GetComponent<Renderer>().material.SetColor("_Color", lerpedColor); }
}
} I've added a bool to turn the flashing on and off. This also serves as a test for another consideration, adding a series of bools to easily set what sorts of traits and modifiers a tile might have, like "difficult terrain" or "damages unit". However, I can't just drag the script onto the tiles as they are generated at runtime. I've added the script to the prefab such that it's always present on the tiles, but I'm not sure how to trigger the bool to "true" during the tile highlighting phase of things. I think most of the trouble is trying to set the value on an instanced object. I'm a nubby nub though so my perception is suspect. Any help would be appreciated!
|
|
|
Post by Admin on Jun 11, 2018 18:14:23 GMT
Take a look at the Board's "SelectTiles" and "DeSelectTiles" methods. I am performing tile highlighting there by simply getting a renderer component from the tile and changing the material color. It would be very simple to instead get your "Flasher" component and set the "flashOn" field accordingly.
|
|
aka
New Member
Posts: 5
|
Post by aka on Jun 11, 2018 19:40:15 GMT
You know, I tried that - it failed - and now I've tried it again and noticed what I'd done wrong. the "i" integer kept reporting an error whenever I added a new line... because I'd been forgetting to add {} to account for the extra instructions. WELP
Thanks though. It works (and looks) perfectly!
|
|