Game Development Reference
In-Depth Information
You've seen what the slug does, so now it's time to define its behavior. As usual, there are several
different things you could do. If it passed through on a regular basis, its speed might be inversely
proportionate to the amount of battery left. The more desperate the player, the faster the slug.
Another option would be to have it appear only when the battery dropped below a certain threshold.
Before deciding, you should do a test or two. Let's begin by using 1/10th of the percent of battery
life for speed, 10%.
1.
Open the slug's Animation Controller, Slug Controller.
2.
Set the Slug Run clip/state to 10 .
3.
Switch to the Scene view, and click Play.
The slug streaks by, leaving only its slime trail. A setting of 1/25th might be more realistic.
4.
Try a Speed of 4 .
It's also pretty fast, but it does have a pause near the middle of the garden, so you could consider
that the top speed.
5.
Set the Speed back to 1 .
With either option, the action will be based on the battery's percent remaining, so it might be a good
idea to plan on instantiating the slug from the BatteryHealth script.
6.
Open the BatteryHealth script, and add the following variables:
public GameObject slug; // the slug prefab
public Transform slugDrop; // this could be updated to the current zone
bool running; // flag for active slug
In the Update function, inside the if (batteryRemaining clause, at the
bottom, add the following:
7.
ManageSlug(); // check to see if the slug should make a run
8.
Create the new function:
void ManageSlug(){
if (percentRemaining == 90 && !running) {
Instantiate (slug,slugDrop.localPosition, slugDrop.localRotation);
running = true;
}
}
9.
Save the script.
10.
For the Battery Life object, assign the Slug prefab from the Project view to
the Slug parameter and the Slug Start object to the Slug Drop parameter.
In case the slug escapes the garden before being hit, you will have to set it to be destroyed when its
run is finished. If it is hit, its Slug Hit state/clip will be triggered.
 
Search WWH ::




Custom Search