Graphics Reference
In-Depth Information
Invoke ( "ResetFire", fireDelayTime );
}
}
}
public void ResetFire ()
{
canFire=true;
}
}
9.3.1 Script Breakdown
BaseArmedEnemy.cs uses the namespace AIAttackStates from the AIAttackStates.cs
script seen earlier in this section. The advantage of using the namespace is that this script
can access the AIAttackStates enumerated list as though it were declared in this class. To
tell Unity that we want to refer to this namespace, we use the using keyword:
using AIAttackStates;
The main BaseArmedEnemy.cs script is derived from ExtendedCustomMono
Behavior, which extends the base functionality of MonoBehavior to include some helper
variables:
public class BaseArmedEnemy : ExtendedCustomMonoBehavior
{
The Start() function calls Init():
public void Start ()
{
// now call our script-specific init function
Init();
}
As with most of the Init() functions in this topic, it starts by caching references to the
gameObject and transform to which this script component is applied:
public void Init()
{
// cache our transform
myTransform= transform;
// cache our gameObject
myGO= gameObject;
This class's prime objective is to manage the weapons system for the AI players, so a
reference to the weapon controller script is essential. If one has not been set in the Unity
editor Inspector window on this script's gameObject, the code below will find out and try
to find it with a call to gameObject.GetComponent():
if(weaponControl==null)
{
// try to find weapon controller on this gameObject
Search WWH ::




Custom Search