Another quick one. This script was built to control and explosion in Nuclear Lizard Island Rampage. Once it spawns into the scene, it grows bigger and bigger before disappearing. I thought it would be a great place to highlight Loop blocks.
So, you can see this script just has a Start block and not an update block. We could have also used and Update block paired with a Cooldown block set to 0.05 seconds, but this is a little cleaner. The Start block goes to the For Loop (an important distinction since there are other Loop blocks) and the block is set to loop 5 times as you can see in the Last slot. This means that the block will fire whatever you have hooked up to the Body output five times before it fires whatever you have hooked up to the Exit output.
In this case, our Body output is tied to a script that increases the size of the object. Note there is a Wait block in between the Loop and Scale blocks. If you don't delay the script, it will effectively fire all of the Body loops all at once, leaving no time for human perception. I wanted the player to register the explosion as getting bigger even if it is very fast, which is why there is the 0.05 second delay between scaling up.
Each time this fires, the script will get the dimensions of the object (Get Local Scale) and add 0.3 in scale to each axis. Note that this Add block is specifically an Vector 3 Add block. A generic Add block will not work. The output of this addition is loaded into the Set Local Scale block and the explosion gets a little bit bigger.
After it loops five times, it will go to the Exit output from the Loop block and the explosion will despawn itself. So, it shows up in the world with a scale of 1-1-1, then quickly grows to 2.5-2.5-2.5, then vanishes.
No comments:
Post a Comment