Game Development Reference
In-Depth Information
totalTime = 0;
yield return NodeResult.Success;
}
The
HangAround
function just makes us wait a few seconds. First, it selects how
long to wait, and then, once this amount of time passes, returns a success. Notice
that we return
NodeResult.Continue
. This tells the script to wait until the next
update and then try to get, then see if it is finished yet. (Yield is used so the game
doesn't freeze up.)
The
MoveToTarget
function isn't given here as it is nearly identical to the function
we used in
Chapter 1
,
Pathfinding
, except that now we are going after the target spe-
cified randomly from
FindTarget
.
Building behavior trees in React
Now that we have our behavior methods, we can build the behavior tree. Right-click
on your project's
Assets
folder and navigate to
Create
|
Reactable
. Rename it to
LookBusyReactable
. Then, right-click on it and select
Edit Reactable
:
The preceding is a screenshot of the behavior tree editor completed. Right-click on
Root
and navigate to
Add
|
Branch
|
Sequence
. This is so it completes each step
before moving on to the next. Right-click on
Sequence
and navigate to
Add
|
Leaf
|
Action
. Do this three times:
1. For the first one, click on the empty checkbox and navigate to
Scripts
|
LookBusy
|
FindTarget
. This is part of the
LookBusy.cs
script that we ad-
ded earlier.
2. Forthesecondone,dothesamebutinsteadnavigateto
Scripts
|
LookBusy
|
MoveToTarget
.