12 years ago

Solving the Unity's Static Invoke Problem With LeanTween


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.

Full Source

White Enabled Sprite Shader *Have to use this if your going to use the methods I made.



0 comments

Loading...

Next up

art comission.

Shoobies leave a sticky trail of mucus in their wake, which can impede movement for any creature that steps in it.

Here's a peaceful little forest scene for this #screenshotsaturday, from the beginning of the game.

Another house i made long time ago.

Updated the chest in the maze, adding sound, particles and better animation. But what's in the chest?

One of the most critical update for Sunblaze demo. Now you are able to pet a cat! Finally!

Horror WIP A track that will be featured in a future horror game soundtrack! Stay tuned!

Likes appreciated ✌️

#gamedev #composer #horrorgame #indiegame #IndieGameDev #soundtrack

Spaaaace~

These are background sprites I've created for a game I'm working on at school ^w^ Click on the post to see how the sprites connect. You won't regret it! (personally, I think it's pretty heheh)

Drawn in Piskel using my mouse. Whaddya think?

brung back my old oc plus a new one

...they don`t have names yet tho

Regional Bulbasaur. #Pokemon