So in unity you can not use the invoke method, a method to execute methods on a delay, in static classes. Normally that is ok but I had already developed a static effect class that will take in gameobjects and put a effect on them. What I wanted to do was flash the sprite to complete white, and to do that I needed to run a method in the sprite’s render component to modify the sprites shader. Which would be ok to do in a static method but I want it to flash back and forth, if I just made 2 methods I would still have to write code for every character/boss to do that. I am using a Unity extension called LeanTween and its pretty awesome, its open source and very lite. In this case I wanted to exploit its On Complete function which is called when the game object finishes its tween move. In order to do that I had to create System.Actions, and I was like what I have never heard of those. Welllll they are like Method Delegates. I thought it would hard to figure out but it was really easy. All you have to do is make static methods like normal where they take the param generic C# obejct. You create them like any other member, new Action(yourMethod); . That is it you have an action! Ok so now that I have all that I can make the flasher. the method takes a game object then tells LeanTween to move that object(LT is instantiated automatically when called), no where, yeah move it to the same spot where it was at. BUT on a delay, so in .4 seconds complete this action. the complete action is turn on white. the next line is the same thing but goes to the off white. Repeat that a few times and you have a flash effect that will work on any sprite( that has this shader). Obviously you may not need it to flash but this is a great way to get around the pesky unity everything has to be a mono behavior to work crap that can get in your way.
White Enabled Sprite Shader *Have to use this if your going to use the methods I made.










0 comments