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.

🍒Did you like the game? A demo is available for free on Steam.

✌️ Thanks for playing IndieGameiacs!

⚙️ Free Demo: http://bit.ly/UniDuni

📺 Full Video: https://youtu.be/5qEbVXg7GaQ

#steam #uniduni #clops #screenshotsaturday

I was bored, so... ManutKat.

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

Update 2.627

New challenges & new effects!

Very ambitious construction going on in Planet Zoo on Plays today. We're tryin'. LIVE: www.twitch.tv/dreamhackplays

Auto-chess meets Clash Royale in an intense strategic battle. Outsmart your opponent, hide your play and crush their armies! Empire Builder just got another major update, check it out! https://gamejolt.com/games/EmpireBuilder/558901

2d lighting experiment

blender animation experimentation, getting the hang of things fast. arms, rig, & gun models by me ofc