Game Development Reference
In-Depth Information
1. Open the PotatoLauncher script.
The loadRate variable is the value you will be changing, so the ScoreKeeper script would require
access to both the PotatoLauncher script and the loadRate variable. In C#, you would have to
make the variable public . That would expose it to the Inspector. You have another option. You
can designate it as internal . This keeps it from being exposed to the Inspector, yet allows it to be
accessed by other scripts.
Change the float loadRate line to:
2.
internal float loadRate = 0.5f; // how often a new projectile can be fired
3.
Save the script.
4.
Back in the ScoreKeeper script, add the following variable:
public PotatoLauncher launcher; // the PotatoLauncher script
Inside the UpdateCounter function, change the print statement contents,
“reward time!”, as follows to test the communication:
5.
print("current rate: " + launcher.loadRate);
6.
Save the script.
The PotatoLauncher script resides deep in the Gnomatic Garden Defender's hierarchy, on the Fire
Point object.
1.
Locate the Fire Point object, and drag it onto the Game Manager's Score
Keeper's Launcher parameter.
2. Click Play, and watch the console as you shoot the zombie bunnies. When
you reach 10 hits, you will see the loadRate value printed in the console.
If this was a simple matter of changing the value, as with a Boolean type, you could change it
directly. But this one not only requires a bit of math, it also has to be clamped so it cannot be
decremented indefinitely. This is a good time to use SendMessage .
Add the following line above the print("current rate:" + line:
3.
launcher.SendMessage("RewardTime", SendMessageOptions.DontRequireReceiver);
Comment out the two print lines.
4.
5.
Save the script.
In the PotatoLauncher script, you will do all the necessary calculations. Let's put a cap of nothing
shorter than 0.1 seconds for the reload time.
In the PotatoLauncher script, create the RewardTime function:
6.
void RewardTime () {
if( loadRate > 0.1f) loadRate -= 0.1f; // decrease the loadRate by 0.1
}
Search WWH ::




Custom Search