Game Development Reference
In-Depth Information
private var rate : float;
function Update () {
if (playerTransform.position.z > 109 && playerTransform.position.z < 126) {
rate = playerTransform.position.z - 104;
gameObject.particleSystem.startSpeed = rate * rateIncrease;
}
}
This code breaks down as follows:
(1) public var playerTransform : Transform;
1.
Declare the public variable playerTransform of type Transform that will hold
the reference to the player character's transform.
(2) public var rateIncrease : float = 1;
2.
Declare the public variable rateIncrease of type float that will allow you to
adjust the rate of change of the blizzard property through the Inspector.
(3) private var rate : float;
3.
Declare the private variable rate of type float that will be used along with the
player character's position to calculate a rate that varies in accordance with
the player character's progress.
(4) if (playerTransform.position.z > 109 && playerTransform.position.z < 126)
4.
This if conditional contains two tests. The first is to test if the player
character's transform position z coordinate is greater than 109, which
means he has entered the blizzard zone. The second is to test if the player
character's transform position z coordinate is greater than 126, meaning he
has exited the blizzard zone on the far side. The && operator represents the
logical AND operator. The first condition AND the second condition must be
true for the entire conditional statement to return a true result. This in turn
causes the subsequent block of code to be executed.
(5) rate = playerTransform.position.z - 104;
5.
The rate variable is assigned the value of the player character's transform
position z coordinate value minus 104. 104 is an arbitrary amount based on
the original value of the Start Speed property being 5, such that when the
player first enters the Blizzard Zone that begins at a z coordinate of 109, the
Start Speed will still be 5.
(6) gameObject.particleSystem.startSpeed = rate * rateIncrease;
Search WWH ::




Custom Search