Game Development Reference
In-Depth Information
3. Next, we will start creaing the irst funcion Awake() using the following code:
//Using Awake to set up parameters before Initialize
public function Awake() : void {
controller = GetComponent(CharacterController);
b_isRun = false;
b_isBackward = false;
b_isJumping = false;
f_moveSpeed = speed;
c_collisionFlags = CollisionFlags.CollidedBelow;
}
4. In this funcion, we set up the necessary parameters before we iniialize it. Then, we
create the Start() funcion and iniialize it as follows:
public function Start() : void {
f_inAirStartTime = Time.time;
}
We use the Start() funcion to set up f_inAirStartTime because we need to
get the ime when we irst start the scene.
5. Next, we will add the scripts to check the stage of our character, such as jumping,
moving backward, on the ground, and in the air. Let's type this as follows:
//Checking if the character hit the ground (collide Below)
public function IsGrounded () : boolean {
return (c_collisionFlags & CollisionFlags.CollidedBelow);
}
//Getting if the character is jumping or not
public function IsJumping() : boolean {
return b_isJumping;
}
//Checking if the character is in the air more than the minimum
time
//This function is to make sure that we are falling not walking
down slope
public function IsAir() : boolean {
return (f_inAirTime > f_minAirTime);
}
//Geting if the character is moving backward
public function IsMoveBackward() : boolean {
return b_isBackward;
}
 
Search WWH ::




Custom Search