Game Development Reference
In-Depth Information
• It also checks if a
splineNodeRoot
has been assigned to the
spline. If it has, this triggers an automatic waypoint / control point in-
stallation into the
SplineMgr
class:
TargetObj = new GameObject();
nHead = 0;
if (splineNodeRoot)
InstallSplineNodes();
7. The
InstallSplineNodes()
method is an internal private method that
takes a GameObject, extracts all child game objects, and then populates the
ControlPoints
list with these GameObjects as waypoints. The algorithm
has three steps.
1. First, the
ControlPoints
list is cleared:
ControlPoints.Clear ();
2. Using an internal function in Unity, we return an array of all the child
objects of the
splineRootNode
:
Transform[] allChildren =
splineNodeRoot.GetComponentsInChildren<Transform>();
3. We iterate over this list of child nodes (as they are the waypoints in
our spline) and add them to the
ControlPoints
list. Note that this
list will include the
splineNodeRoot
, so we need to check that we
don't add this to the waypoints:
foreach (Transform child in
allChildren)
{
// do what you want with the
transform
if (child !=
splineNodeRoot.transform)