private void Awake() { // Put this in awake in order to fix null reference bug switchController = GetComponent <WeaponSwitchController>(); }
// FUNCTIONS public override void Start() { // base.Start(); // Make sure this start method is similar to the one used in Character.cs // Subscribe to manager every scene load because previous Player is cleared. // SubscribeManager(); // If scene was loaded manually, load information from gameData /* * if (SaveLoadManager.instance.sceneLoadedManually) { * SaveLoadManager.instance.LoadSpecific(GetComponent<SaveableObject>()); * } */ // TODO: Save variables like health, ammo, between levels, but set location and rotation to default anim = characterMesh.GetComponent <Animator>(); mainPlayerAnim = this.GetComponent <Animator>(); characterController = GetComponent <CharacterController>(); playerController = GetComponent <PlayerController>(); switchController = GetComponent <WeaponSwitchController>(); weapons = switchController.inventoryWeapons; // For testing purposes only // Locking and instantiating weapons // weapons[0].locked = false; if (HasWeapon()) { InstantiateWeapon(weapons[0].weaponPrefab); } else { InstantiateWeapon(emptyWeaponPrefab); } // Create weapon clips with full ammo ammoClips = new int[weapons.Length]; for (int i = 0; i < weapons.Length; i++) { ammoClips[i] = weapons[i].weaponPrefab.clipsize; } // Instantiate melee weapon meleeWeapon = Instantiate(switchController.meleeWeapon.weaponPrefab); meleeWeapon.character = this; // Instantiate grenade launcher grenadeLauncher = Instantiate(switchController.grenadeLauncher.weaponPrefab); grenadeLauncher.character = this; effectiveSpeed = speed; collectedKeys = new List <int>(); currentInteractable = null; // Apply loaded data if (Managers.SaveLoad.sceneLoadMethod == SceneLoadMethod.ManualLoad) { ApplyLoadedData(); } }