Game Development Reference
In-Depth Information
if (!_isHitRadius) {
_isHitRadius = true;
_wayIndex = _nextIndex;
if (isRandom) {
int _randomWay =
Mathf.FloorToInt(Random.value * _wayLength);
if (_wayLength > 1) {
while (_wayIndex == _randomWay) {
_randomWay =
Mathf.FloorToInt(Random.value * _wayLength);
}
}
_nextIndex = _randomWay;
} else {
_nextIndex = (_nextIndex + 1) % _wayLength;
}
}
} else {
_isHitRadius = false;
}
Vector3 currentPosition = new Vector3
(myTransform.position.x,
waypoints[_nextIndex].transform.position.y,
myTransform.position.z);
_direction =
(waypoints[_nextIndex].transform.position -
currentPosition).normalized;
return _direction;
}
7. The last function of this script is the OnDrawGizmos() function, which will
only be used in the editor or debugging process, similar to the one we use on the
Waypoint script. We will use this function to draw the line direction between
each waypoint. Let's add it as follows:
// Unity JavaScript user:
function OnDrawGizmos ()
{
Search WWH ::




Custom Search