Graphics Reference
In-Depth Information
{
if( currentState==AIAttackState.random_fire )
{
// if the random number is over x,
// fire
if( Random.Range(0,100)>98 )
{
doFire=true;
}
} else if( currentState==AIAttackState.
look_and_destroy )
{
if(Physics.Raycast( myTransform.
position, myTransform.forward, out
rayHit ))
{
// is it an opponent to be
// shot at?
if( rayHit.transform.CompareTag
( tagOfTargetsToShootAt ) )
{
// we have a match on the tag, so
// let's shoot at it
doFire=true;
}
}
} else {
// if we're not set to random fire or look and
// destroy, just fire whenever we can
doFire=true;
}
}
if( doFire )
{
// we only want to fire if we are on screen, visible on the
// main camera
if(onlyFireWhenOnscreen && !rendererToTestAgainst.
IsVisibleFrom( Camera.mainCamera ))
{
doFire=false;
return;
}
// tell weapon control to fire, if we have a
// weapon controller
if(weaponControl!=null)
{
// tell weapon to fire
weaponControl.Fire();
}
// set a flag to disable firing temporarily
// (providing a delay between firing)
canFire= false;
// invoke a function call in <fireDelayTime>
// to reset canFire back to true, allowing
// another firing session
Search WWH ::




Custom Search