Graphics Reference
In-Depth Information
Boolean variable isLoaded. A timed call to the Reloaded() function, after firing, will reset
the weapon state again:
public virtual void Reloaded()
{
// the 'isLoaded' var tells us if this weapon is loaded and
// ready to fire
isLoaded= true;
}
SetCollider() is used to set a collider to be ignored by a projectile. For example, when
the script is applied to a player, it should ignore the player's collider so as to prevent the
newly created projectile from exploding instantly. It should be set, using the Unity editor
Inspector window, to a collider that would likely destroy the projectile as it was spawned.
If no parentCollider is set, the script will still work, but the projectile will not ignore any
collider:
public virtual void SetCollider( Collider aCollider )
{
parentCollider= aCollider;
}
The Fire() function takes two parameters, a Vector3 to represent the direction of fire
and an integer providing an ID number for its owner (which gets used primarily by colli-
sion code to know how to react):
public virtual void Fire( Vector3 aDirection, int ownerID )
{
The Boolean variable canFire needs to be true (the weapon is allowed to fire) and
isLoaded needs to be true also (the weapon is ready to fire) before the function can pro-
gress to check the state of ammunition:
// be sure to check canFire so that the weapon can be
// enabled or disabled as required!
if( !canFire )
return;
// if the weapon is not loaded, drop out
if( !isLoaded )
return;
If the integer variable ammo is less than zero and the Boolean isInfiniteAmmo has
not been set in the Unity editor Inspector window to true, then the function will drop out
here, too:
// if we're out of ammo and we do not have infinite ammo,
// drop out...
if( ammo<=0 && !isInfiniteAmmo )
return;
Since all of the criteria have been met, the function goes ahead and decrements ammo
in anticipation of the projectile about to be generated by the FireProjectile() function. The
Search WWH ::




Custom Search