Graphics Reference
In-Depth Information
weaponControl= myGO.GetComponent<Standard_SlotWeapon
Controller>();
}
The option is provided with this class to only fire the weapon when a specified renderer
is on screen. The intention is that the main enemy mesh renderer is used for this, so that
weapon firing only happens when the enemy is on screen. If the variable (of type Renderer)
renderToTestAgainst has not been set in the Unity editor Inspector window, the code here
uses GameObject.GetComponentInChildren() to try and find a renderer to use instead:
if(rendererToTestAgainst==null)
{
// we need a renderer to find out whether or not we
// are on screen, so let's try and find one in our
// children if we don't already have one set in the
// editor
rendererToTestAgainst= myGO.GetComponentInChildren
<Renderer>();
}
The player manager for this enemy will be used to deal with this enemy's health
amount. The enemy is not technically a player, but as it does share some scripts and behav-
iors, the lines become blurry and some logic is interchangeable between the two types.
Since it is going to be firing projectiles, it may be likely that it will be receiving hits
from them, too. The BaseArmedEnemy.cs script itself does not manipulate health, but in
Chapter 14, you will see how a script derived from this one will add full support for health
and hits.
myPlayerManager holds a reference to the BasePlayerManager script, which will also
be populated in this code if it has not been set in the Unity editor Inspector window (mak-
ing its value null):
// if a player manager is not set in the editor, let's try
// to find one
if(myPlayerManager==null)
{
myPlayerManager= myGO.AddComponent
<BasePlayerManager>();
}
Once the reference to the player manager script has been made, some default proper-
ties are set up for this enemy, including an integer amount used for health from the vari-
able thisEnemyStrength:
myDataManager= myPlayerManager.DataManager;
myDataManager.SetName("Enemy");
myDataManager.SetHealth(thisEnemyStrength);
With the Init() function complete, canFire allows this enemy to fire from now on and
didInit is set to true so that other functions or scripts can tell that this Init() function has
been completed:
canFire=true;
didInit=true;
}
Search WWH ::




Custom Search