C# Game Programming Cookbook for Unity 3D / Программирование игр на Unity 3D C#. Книга готовых решений.: 9.2.1 Разбор скрипта

Оглавление
← →
Английский оригинал Перевод на русский

Сожалеем, но текст оригинала доступен только зарегистрированным пользователям.

using UnityEngine;
using System.Collections;
using AIStates;

ilia1395 25.10.14 в 20:36

0

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;

ilia1395 25.10.14 в 20:37

0

// init done!
didInit= true;
}

ilia1395 25.10.14 в 20:37

0

public void SetAIControl( bool state )
{
AIControlled= state;
}

ilia1395 25.10.14 в 20:37

0

Функции чтобы установить их следующем образом:

ilia1395 25.10.14 в 20:38

0

// 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;
}

ilia1395 25.10.14 в 20:38

0

public virtual void SetAIState( AIState newState )
{ // update AI state
currentAIState= newState;
}

ilia1395 25.10.14 в 20:39

0

public virtual void SetChaseTarget( Transform theTransform )
{ // set a target for this AI to chase, if required
followTarget= theTransform;
}

ilia1395 25.10.14 в 20:39

0

public virtual void Update ()
{ // make sure we have initialized before doing anything if( !didInit )
Init ();

ilia1395 25.10.14 в 20:39

0

// check to see if we’re supposed to be controlling the player if( !AIControlled )
return;
// do AI updates
UpdateAI();
}

ilia1395 25.10.14 в 20:39

0

public virtual void UpdateAI()
{

ilia1395 25.10.14 в 20:39

0

// reset our inputs
horz=0;
vert=0;

ilia1395 25.10.14 в 20:40

0

0 Нет никаких препятствий не было.

ilia1395 25.10.14 в 20:40

0

int obstacleFinderResult= IsObstacleAhead();

ilia1395 25.10.14 в 20:43

0

switch( currentAIState )
{
// -----------------------------

ilia1395 25.10.14 в 20:49

0

// look for chase target
if( followTarget!=null )

ilia1395 25.10.14 в 20:49

0

LookAroundFor( followTarget );

ilia1395 25.10.14 в 20:49

0

// 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 );
}

ilia1395 25.10.14 в 20:49

0
Минутку...

Следующая страница →