Learn Unity 4 for iOS Game Development by Philip Chu

Learn Unity 4 for iOS Game Development by Philip Chu

Author:Philip Chu
Language: eng
Format: epub, mobi, pdf
Publisher: Apress, Berkeley, CA


At some point, the SmoothFollow and FuguForce scripts have to be reenabled. The natural place to do that is in the ResetCamera and ResetBall functions (Listing 8-23), as they get called when a roll is over and the Main Camera and Ball, respectively, are reset to start another roll.

Listing 8-23. ResetBall and ResetCamera Functions in FuguBowl.js

function ResetBall() {

ball.GetComponent(FuguForce).enabled = true;

ball.SendMessage("ResetPosition");

}

function ResetCamera() {

var follow:Behaviour = Camera.main.GetComponent("SmoothFollow");

if (follow != null) {

follow.enabled = true;

}

Camera.main.SendMessage("ResetPosition");

}

In both the ResetBall and ResetCamera functions, the code to enable the script Component is the same one used to disable the script, except the enabled variable is set to true.

After disabling both the FuguForce and SmoothFollow scripts, StateRolledPast waits five seconds before transitioning to the next state, StateRollOver, allowing time for the Ball to roll into the pins (or past the pins). A while loop that calls yield until the desired amount of time has passed (by checking Time.time) would do the trick, but it’s much more convenient to call yield on the function WaitForSeconds, which takes a number of seconds as an argument (in StateRolledPast, the number of seconds is hardcoded to 5, but it could easily be a public variable to allow customization). As a result, the coroutine StateRolledPast will essentially pause (without blocking execution in the rest of Unity) until the given time has elapsed.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.