Готовый перевод C# Game Programming Cookbook for Unity 3D / Программирование игр на Unity 3D C#. Книга готовых решений.: 9.2.1 Разбор скрипта
using UnityEngine;
using System.Collections;
using AIStates;
public virtual void Init ()
{ // cache ref to gameObject
myGO= gameObject;
// cache ref to transform
myTransform= transform;
// cache a ref to our rigidbody
myBody= myTransform.rigidbody;
// init done!
didInit= true;
}
public void SetAIControl( bool state )
{
AIControlled= state;
}
Функции чтобы установить их следующем образом:
// set up AI parameters --------------------
public void SetPatrolSpeed( float aNum )
{
patrolSpeed= aNum;
}
public void SetPatrolTurnSpeed( float aNum )
{
patrolTurnSpeed= aNum;
}
public void SetWallAvoidDistance( float aNum )
{
wallAvoidDistance= aNum;
}
public void SetWaypointDistance( float aNum )
{
waypointDistance= aNum;
}
public void SetMoveSpeed( float aNum )
{
moveSpeed=aNum;
}
public void SetMinChaseDistance( float aNum )
{
minChaseDistance= aNum;
}
public void SetMaxChaseDistance( float aNum )
{
maxChaseDistance= aNum;
}
public void SetPathSmoothing( float aNum )
{
pathSmoothing= aNum;
}
public virtual void SetAIState( AIState newState )
{ // update AI state
currentAIState= newState;
}
public virtual void SetChaseTarget( Transform theTransform )
{ // set a target for this AI to chase, if required
followTarget= theTransform;
}
public virtual void Update ()
{ // make sure we have initialized before doing anything if( !didInit )
Init ();
// check to see if we’re supposed to be controlling the player if( !AIControlled )
return;
// do AI updates
UpdateAI();
}
public virtual void UpdateAI()
{
// reset our inputs
horz=0;
vert=0;
0 Нет никаких препятствий не было.
int obstacleFinderResult= IsObstacleAhead();
switch( currentAIState )
{
// -----------------------------
// look for chase target
if( followTarget!=null )
LookAroundFor( followTarget );
// the AvoidWalls function looks to see if there’s
// anything in front. If there is, it will
// automatically change the value of moveDirection
// before we do the actual move
if( obstacleFinderResult==1 ){ // GO LEFT
SetAIState( AIState.stopped_turning_left );
}
if( obstacleFinderResult==2 ){ // GO RIGHT
SetAIState( AIState.stopped_turning_right );
}
Внимание! Этот перевод, возможно, ещё не готов.
Его статус: идёт перевод
Переведено на Нотабеноиде
http://notabenoid.org/book/55263/242529
Переводчики: ilia1395
Настройки
Готово:
