Game Development Reference
In-Depth Information
3. Now we will create the Awake() funcion to set up the necessary values for
our parameter before it gets iniialized in the Start() funcion, so add the
following code:
//Using Awake to set up parameters before Initialize
public function Awake() : void {
controller = GetComponent(CharacterController);
b_isRun = false;
b_isAiming = false;
b_isJumping = false;
f_moveSpeed = walkSpeed;
c_collisionFlags = CollisionFlags.CollidedBelow;
f_moveSpeed = walkSpeed;
//To make the character stop moving at a certain time
f_lastTime = Time.time; //Tracking the time between each
movement of the character
b_isStop = false;
aiMaxHP = aiHP;
//Set up animation speed and wrapmode
_animation[walkAnimation.name].speed = walkAnimationSpeed;
_animation[walkAnimation.name].wrapMode = WrapMode.Loop;
_animation[runAnimation.name].speed = runAnimationSpeed;
_animation[runAnimation.name].wrapMode = WrapMode.Loop;
_animation[idleAnimation.name].speed = idleAnimationSpeed;
_animation[idleAnimation.name].wrapMode = WrapMode.Loop;
}
In the preceding Awake() funcion, we just assigned the value of each parameter,
set up the movement speed, animaion clip speed, animaion wrapmode of the
enemy, and the current ime, which we will use to calculate the ime to stop the
enemy or make him walk.
4. Next, add the following Start() funcion to set the posiion of our enemy equal to
the irst waypoint posiion:
//Initialize
public function Start() : void {
transform.position = wayPoint.StartPosition();
}
 
Search WWH ::




Custom Search