Game Development Reference
In-Depth Information
13. As the last step of the Update() funcion, we will add the script for the game over
state and close our funcion as follows:
} else {
//Gameover
_animation.CrossFade(idleAnimation.name);
}
}
14. Then, we will add two funcions, which will be used to control the aiming and
shoot animaions:
//Wait for shoot animation
private function WaitForShot () : IEnumerator {
_animation[shotAnimation.name].speed = shotAnimationSpeed;
_animation[shotAnimation.name].wrapMode = WrapMode.ClampForever;
_animation.PlayQueued(shotAnimation.name, QueueMode.PlayNow);
BroadcastMessage("Fire", shotAnimation.length); //to enable all
the function name Fire in every MonoBehaviour Script
yield WaitForSeconds (shotAnimation.length);
b_isShot = false;
}
//Wait for aiming animation
private function WaitForPrepare () : IEnumerator {
_animation[shotAnimation.name].speed = shotAnimationSpeed * 2;
_animation[shotAnimation.name].wrapMode = WrapMode.ClampForever;
_animation.CrossFade(shotAnimation.name, 0.6);
yield WaitForSeconds(shotAnimation.length);
b_isPrepare = true;
}
15. The last funcion that we add is the OnDrawGizmos() funcion, which we used in
the last step to draw the line between the player posiion and the enemy posiion:
//Draw Gizmos and Directional line from the enemy position to the
player position
public function OnDrawGizmos() : void {
if (player != null) {
Gizmos.color = Color.blue;
Gizmos.DrawLine(transform.position, player.position);
}
}
 
Search WWH ::




Custom Search