Graphics Reference
In-Depth Information
{
selectedWeaponSlot= weaponScripts.Count-1;
} else {
selectedWeaponSlot= 0;
}
}
// we store this selected slot to use to prevent duplicate
// weapon slot setting
lastSelectedWeaponSlot=selectedWeaponSlot;
// enable the newly selected weapon
EnableCurrentWeapon();
}
Disabling the current weapon means that it will be both invisible and unable to fire:
public virtual void DisableCurrentWeapon ()
{
To disable the weapon, the script will need to talk to the BaseWeaponScript.cs attached
to it. Since weaponScripts and weaponSlots ArrayLists were created in the same order, the
selectedWeaponSlot can be used as the index for either array.
To make sure that there are scripts in the weaponScripts array, its Count property is
checked before going any further:
if(weaponScripts.Count==0)
return;
A reference to the currently selected weapon slot's weapon script (BaseWeaponScript.
cs) is stored in the variable TEMPWeapon as it is retrieved from the weaponScripts
ArrayList:
// grab reference to currently selected weapon script
TEMPWeapon= ( BaseWeaponScript )weaponScripts[selectedWeapon
Slot];
To tell the weapon to disable, it's a call to its Disable() function:
// now tell the script to disable itself
TEMPWeapon.Disable();
As well as disabling the actual weapon script, it now needs to be hidden from view.
First, the variable TEMPgameObject receives a reference to the weapon's gameObject
from the weaponSlots ArrayList. The TEMPgameObject variable is then set to inactive by
GameObject.SetActive():
// grab reference to the weapon's gameObject and disable
// that, too
TEMPgameObject= ( GameObject )weaponSlots[selectedWeaponSlot];
TEMPgameObject.SetActive( false );
}
Search WWH ::




Custom Search