Game Development Reference
In-Depth Information
the flock, but we'll take the simplest route and use a game manager. Create another
empty GameObject and call it GameManager . Then, create a new script, GameMan-
ager.cs , and attach it to the GameManager object.
Add the following code to it:
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
public Transform target;
void Start () {
}
void Update () {
FlockGroup group =
FameManager.GetFlockGroup(1); // Get first flock
group.MoveGroupAbs(target.position);
}
}
In this code, we have a public variable for the target for the flock. In the Unity editor,
drag the Sphere target object to this field to set its value. Then, in the update, we just
get the flock group from Fame manager (which is a singleton class with static meth-
ods, so we don't need a reference to it). Then, we just use MoveGroupAbs that tells
the group to move to a specific location. (There is also a method called MoveGroup
that takes in an offset instead of an absolute position you can use if you want the
crowd to move in a general direction instead of to a specific point.) If you run the
demo now, the ships will travel down the ground to the target point. As you can see,
setting up a crowd and giving directions for it to move is very easy and straightfor-
ward with Fame.
Search WWH ::




Custom Search