Game Development Reference
In-Depth Information
void Awake () {
_animator = GetComponent<Animator>();
_characterController =
GetComponent<CharacterController>();
}
4. Then, we create the
Start()
function and set up all the variables as follows:
// Unity JavaScript user:
function Start () {
_moveDirection = Vector3.zero;
_motionState = MOTION_STATE.GROUND;
_isRun = false;
_isMoveBack = false;
_moveSpeed = 0.0f;
_verticalSpeed = 0.0f;
_inAirTime = 0.0f;
_inAirStartTime = Time.time;
}
// C# user:
void Start () {
_moveDirection = Vector3.zero;
_motionState = MOTION_STATE.GROUND;
_isRun = false;
_isMoveBack = false;
_moveSpeed = 0.0f;
_verticalSpeed = 0.0f;
_inAirTime = 0.0f;
_inAirStartTime = Time.time;
}
5. Next, we will create the
Update()
function. In this function, we will calculate
all movements for our character. First, we will use
input
and
_targetDir-
ection
by using the
main camera
transform to calculate
_moveDirec-
tion
as follows: