Game Development Reference
In-Depth Information
}
}
Here, we loop through how many Goblins we'll need, create a new instance using the pre-
fab we created earlier, set its position off screen, and then animate it on to the screen using
yet another coroutine (shown in the following code). When the coroutine finishes animat-
ing, we anchor it to the spawn point it was meant for.
Note
I made the Enemy prefabs into an array, so we can support multiple types of enemies in
the battle.
So that the Goblins don't appear, we use the AnimationCurve parameter we added to
the script and a coroutine to move the Goblin from off screen to its intended spawn point,
as follows:
IEnumerator MoveCharacterToPoint(GameObject destination,
GameObject character)
{
float timer = 0f;
var StartPosition = character.transform.position;
if (SpawnAnimationCurve.length > 0)
{
while (timer < SpawnAnimationCurve.keys[
SpawnAnimationCurve.length - 1].time)
{
character.transform.position =
Vector3.Lerp(StartPosition,
destination.transform.position,
SpawnAnimationCurve.Evaluate(timer));
timer += Time.deltaTime;
yield return new WaitForEndOfFrame();
}
}
else
{
character.transform.position =
Search WWH ::




Custom Search