Game Development Reference
In-Depth Information
if (!b_isPrepare) {
b_isShot = false;
//Play the shot preparing animation function
WaitForPrepare();
} else {
//If the player click fire play the shot animation again
if ((Input.GetButton("Fire1")) && (!b_isShot)) {
b_isShot = true;
//Play the shot animation function
WaitForShot();
}
}
//No Movement Direction
motor.inputMoveDirection = Vector3.zero;
}
7. Go to the
else
secion and add the highlighted code at the irst line before
if
(Camera.main.GetComponent(MouseLook)) {
, as follows:
else {
//Hide the Scope UI
scopeUI.enabled = false;
//Set the prepare animation to false
b_isPrepare = false;
//No Y-axis Rotation
mouseLook.minimumY = 0;
mouseLook.maximumY = 0;
//Change the movement speed of the character
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.
RightShift)) {
8. We are now done with the adding part for the
Update()
funcion. We will need to
add other two funcions for the
WaitForPrepare()
and
WaitForShot()
funcions.
So, let's go to the
Update()
funcion before
@script RequireComponent
(CharacterMotor)
line and add the following two funcions:
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); //Call Fire
function in attached scripts of this GameObject or any of its
children