Game Development Reference
In-Depth Information
destination.transform.position;
}
}
Using the same logic we used in the previous chapter when moving the character on the
map, we work out where the game object is starting from and then use a while loop to
keep the game object moving until it finally reaches its destination. However, to improve
things, this time we base the loop on the length of the AnimationCurve parameter we
have defined for this transition.
This allows greater flexibility and allows us to have more complex and longer animations.
• First we check whether there are animation steps (keys) within Anima-
tionCurve (if you want something to just pop in to place, then don't configure
a curve)
• If there are keys in the animation, then we keep iterating until we reach the last
key in the animation based on the time of that step and our current iteration time
Then within the loop, we use Lerp for the position of the object from start to finish using
the animation curve to control its time and rate.
Note
We only go to the next animation step when the next frame is ready (using the
WaitForEndOfFrame function) else the animation would happen all at once; so we do
it gradually each frame.
You could use yield return null ; however, this happens indeterminately and could
cause the coroutine to be called several times per frame depending on how long the last
render/draw took. Since this is a smooth animation, we need to process it for each frame.
If it is another operation that just needs controlled cycles/iterations, returning null may
be preferred.
Next, we need to give the player a way to interact with the battle scene, so we'll add some
GUI buttons that only appear if we are in the player's battle phase. We need the following
code to do this:
void OnGUI()
{
if (phase == BattlePhase.PlayerAttack)
Search WWH ::




Custom Search