Graphics Reference
In-Depth Information
public void Start ()
{
// default to the first weapon slot
selectedWeaponSlot= 0;
lastSelectedWeaponSlot= -1;
// initialize weapon list ArrayList
weaponSlots= new ArrayList();
// initialize weapon scripts ArrayList
weaponScripts= new ArrayList();
// cache a reference to the transform (looking up a
// transform each step can be expensive, so this is important!)
myTransform= transform;
if(forceParent==null)
{
forceParent= myTransform;
}
// rather than look up the transform position and rotation
// of the player each iteration of the loop below,
// we cache them first into temporary variables
TEMPvector3= forceParent.position;
TEMProtation= forceParent.rotation;
// we instantiate all of the weapons and hide them so that
// we can activate and use them
// when needed.
for( int i=0; i<weapons.Length; i++ )
{
// Instantiate the item from the weapons list
TEMPgameObject= (GameObject) Instantiate( weapons[i],
TEMPvector3 + offsetWeaponSpawnPosition,
TEMProtation );
// make this gameObject that our weapon controller
// script is attached to, to be the parent of the
// weapon so that the weapon will move around
// with the player
// NOTE: if you need projectiles to be on a
// different layer from the main gameObject, set the
// layer of the
// forceParent object to the layer you want
// projectiles to be on
TEMPgameObject.transform.parent= forceParent;
TEMPgameObject.layer= forceParent.gameObject.layer;
TEMPgameObject.transform.position= forceParent.
position;
TEMPgameObject.transform.rotation= forceParent.
rotation;
Search WWH ::




Custom Search