Game Development Reference
In-Depth Information
newBullet.transform.position = bulletSpawnTransform.position;
// Acquire the PlayerBulletController component on the new object
// so we can specify some data
PlayerBulletController bullCon = newBullet.GetComponent<PlayerBulletC
ontroller>();
// Set the player object
bullCon.playerObject = gameObject;
// Launch the bullet!
bullCon.launchBullet();
// With the bullet made, set the state of the player back to the
// current state
onStateChange(currentState);
With the preceding code, we now create the bullet, set its needed properties, and
then reset the player back to the previous state, all in one shot. We also need to make
sure that the checkForValidStatePair method allows this to pass. So, go ahead
and add the following code inside this method in PlayerStateListener :
PlayerStateController.playerStates.firingWeapon:
returnVal = true;
break;
We also need to change a few states to allow firingWeapon to occur while they
are active. So, be sure to add the following code to the state comparisons in
checkForValidStatePair for the states of jump , landing , and falling :
|| newState == PlayerStateController.playerStates.firingWeapon
Finally, all we need to do now is set up the code to actually trigger all this to happen
whenever the button is clicked. Open up PlayerStateController, and in the bottom
part of LateUpdate , add the following code:
float firing = Input.GetAxis("Fire1");
if(firing > 0.0f)
{
if(onStateChange != null)
onStateChange(PlayerStateController.playerStates.firingWeapon);
}
 
Search WWH ::




Custom Search