Graphics Reference
In-Depth Information
AIControlComponent= GetComponent<BaseAIController>();
myGO= gameObject;
myTransform= transform;
// quick null check, to warn us if something goes wrong
if( AIControlComponent == null )
{
Debug.LogWarning("SetAIChaseTargetBasedOnTag cannot
find BaseAIController");
}
InvokeRepeating( "LookForChaseTarget", 1.5f, 1.5f );
}
void LookForChaseTarget ()
{
// null check
if( AIControlComponent == null )
return;
GameObject[] gos = GameObject.FindGameObjectsWithTag
( defaultTagFilter );
// Iterate through them
foreach ( GameObject go in gos )
{
if( go!= myGO ) // make sure we're not comparing
// ourselves to ourselves
{
float aDist =
Vector3.Distance( myGO.transform.position,
go.transform.position );
if(checkForWalls)
{
// wall check required
if( CanSee( go.transform )==true )
{
AIControlComponent.SetChaseTarget( go.transform );
foundTarget= true;
}
} else {
// no wall check required! go ahead
// and find something to chase!
if( aDist< chaseDistance )
{
// tell our AI controller to
// chase this target
AIControlComponent.SetChaseTarget( go.transform );
foundTarget= true;
}
}
}
}
if( foundTarget==false )
Search WWH ::




Custom Search