Game Development Reference
In-Depth Information
float _inAirStartTime;
public bool IsMoveBackward {
get { return _isMoveBack; }
}
public bool IsGrounded {
get { return _characterController.isGrounded; }
}
public bool IsFall {
get { return (_inAirTime > MIN_AIR_TIME); }
}
}
Here, we have all the necessary parameters to use in our script. In the first line,
we want to make sure that we have the CharacterController and Animator
components attached when we use this script. Then, we have the enum variable,
which we will use to set the state of the animation clip. (The enums are integer
values that start from 0,1,2….) Next, we have the animation speed to control how
fast the character rotation and movement should be.
We have the GRAVITY property because we will use it to calculate the Move()
function in the CharacterController class. In the last three functions, we
basically have the get function to return if our character is moving backward, on
the ground, or is falling. For the IsFall() function, we basically check wheth-
er our character stays in the air longer than MIN_AIR_TIME .
3. Next, we will start creating the first function, Awake() , using the following code
to get the _animator and _characterController components:
// Unity JavaScript user:
function Awake () {
_animator = GetComponent.<Animator>();
_characterController =
GetComponent.<CharacterController>();
}
// C# user:
Search WWH ::




Custom Search