Game Development Reference
In-Depth Information
we have so far. Therefore, in this case we set the value of the nearest target to current target
(lines 38 through 40). The last step in Start() is to store the nearest target that we have found
in currentTarget (line 45).
In Update() function of TargetFollower , we make sure that the current target is not null,
which means it has a value stored in it. The current can be null when there are not targets
in the scene, and therefore no nearest target or current target. After that, we check the
current target to test if it has already been hit by another rocket or a bullet. A quick
hint regarding && operator in line 52: this operator is called “And”, and it requires both
operands to be true in order to return a true. However, if the first operand is false, the
second is not going to be evaluated. This behavior is necessary in this case, because we
cannot check nearestTarget.hit if nearestTarget it self is null, otherwise we get an error.
Search WWH ::




Custom Search