Game Development Reference
In-Depth Information
public bool Run () {
float distanceToPlayer =
(targetLookat.position -
transform.position).sqrMagnitude;
float runDistance =
(playerRange+shotRange)*(playerRange+shotRange);
float shotDistance = shotRange*shotRange;
if ((distanceToPlayer <= runDistance) &&
(distanceToPlayer > shotDistance)) {
return true;
}
return false;
}
◦ In the last function, to control the enemy behavior, we will make our en-
emy walk and stop for a certain amount of time:
// Unity JavaScript user:
function IsThinking() : boolean {
if (IsAiming) {
_lastTime = Time.time;
_isThinking = false;
return false;
}
var time : float;
if (_isThinking) { time = thinkingTime; }
else { time = walkingTime; }
if (Time.time >= (_lastTime + time)) {
_isThinking = !_isThinking;
_lastTime = Time.time;
}
return _isThinking;
}
// C# user:
Search WWH ::




Custom Search