void Awake()
{
Controller = transform.root.GetComponent<CharacterController>();
transform.localPosition = m_LocalPosition;
// detect angle of camera at moment of startup. this will be added to all mouse
// input and is needed to retain initial rotation set by user in the editor.
m_InitialRotation = new Vector2(transform.eulerAngles.y, transform.eulerAngles.x);
// set parent gameobject layer to 'Player', so camera can exclude it
/*transform.parent.gameObject.layer = vp_Layer.Player;
foreach (Transform b in transform.parent.transform)
{
b.gameObject.layer = vp_Layer.Player;
}*/
// set own culling mask to render everything except body and weapon
camera.cullingMask &= ~((1 << vp_Layer.Player) | (1 << vp_Layer.Weapon));
// set own depth to '0'
camera.depth = 0;
// add the gameobjects of any weapon components to the weapon list,
// and make them inactive
Component[] weaponComponents;
weaponComponents = GetComponentsInChildren<vp_FPSWeapon>();
foreach (vp_FPSWeapon comp in weaponComponents)
{
m_Weapons.Insert(m_Weapons.Count, comp.gameObject);
comp.gameObject.SetActiveRecursively(false);
}
// sort the weapons alphabetically. this allows the user to
// order them by putting e.g. a number at the beginning of
// their names in the hierarchy.
IComparer comparer = new WeaponComparer();
m_Weapons.Sort(comparer.Compare);
// create springs for camera motion
// primary position spring
// this is used for all sorts of positional force acting on the camera
m_PositionSpring = new vp_Spring(gameObject.transform, vp_Spring.TransformType.Position);
m_PositionSpring.MinVelocity = 0.00001f;
m_PositionSpring.RestState = PositionOffset;
// secondary position spring
// this is mainly intended for positional force from recoil, stomping and explosions
m_PositionSpring2 = new vp_Spring(gameObject.transform, vp_Spring.TransformType.PositionAdditive);
m_PositionSpring2.MinVelocity = 0.00001f;
// rotation spring
// this is used for all sorts of angular force acting on the camera
m_RotationSpring = new vp_Spring(gameObject.transform, vp_Spring.TransformType.RotationAdditive);
m_RotationSpring.MinVelocity = 0.00001f;
// initialize weapon sorting by activating weapon 1 (if present)
if (m_Weapons.Count > 0)
SetWeapon(1);
RefreshSettings();
//m_AudioListener = (AudioListener)gameObject.AddComponent("AudioListener");
}