Graphics Reference
In-Depth Information
if(weaponScripts.Count==0)
return;
// find the weapon in the currently selected slot
TEMPWeapon= ( BaseWeaponScript )weaponScripts[selectedWeapon
Slot];
theDir = myTransform.forward;
if( useForceVectorDirection )
theDir = forceVector;
// fire the projectile
TEMPWeapon.Fire( theDir, ownerNum );
}
}
6.1.1.1 Script Breakdown
The BaseWeaponController class derives from MonoBehavior, utilizing the usual built-in
Unity calls (Start(), Update(), FixedUpdate(), etc.):
public class BaseWeaponController : MonoBehavior
{
Skipping down, past the declarations, to the Start() function, default values are set for
the currently selected weapon slot, and the last selected weapon and ArrayList arrays are
initialized ready to hold different weapon(s). When the lastSelectedWeaponSlot variable
is set to −1, it just lets the weapon system know that it needs to set the weapon (to avoid
duplicate calls later on, whenever the weapon slot is set, it checks to make sure that the
new weapon it is trying to set is different to the one currently set up—hence the −1 to make
the values of selectedWeaponSlot versus lastSelectedWeaponSlot different on initialization):
// default to the first weapon slot
selectedWeaponSlot= 0;
lastSelectedWeaponSlot= -1;
// initialize weapon list ArrayList
weaponSlots= new ArrayList();
// initialize weapon scripts ArrayList
weaponScripts= new ArrayList();
Transforms are cached into myTransform, and the variable forceParent is populated
with myTransform if it has not been set in the Unity editor Inspector window. The idea here
is that there may be occasions where the required parent transform of the weapon may not
always be the transform to which this script is attached. The weapon's parent transform may
be set by dragging a reference into forceParent from within the Unity editor:
Search WWH ::




Custom Search