示例#1
0
    void SetupWeaponInventory()
    {
        // If not empty
        if (WeaponsInventory.Count > 0)
        {
            WeaponsInventory.Clear();
        }
        // Add all weapons
        var weapons = GameObject.FindGameObjectsWithTag("Weapon");

        // Adding all the weapons to the inventory
        foreach (var weapon in weapons)
        {
            var weaponScript = weapon.GetComponent <Weapon>();
            WeaponsInventory.Add(weaponScript.WeaponID, weaponScript);
            // Set all weapons besides the currently equipped one to inactive
            if (weaponScript.WeaponID == ActiveWeaponID)
            {
                // Set ammo to the first weapon
                weapon.SetActive(true);
                weaponScript.setAmmoText();
            }
            else
            {
                weapon.SetActive(false);
            }
        }
    }
示例#2
0
 void UnlockWeapon(int weaponID)
 {
     // ONly run if the weapon isnt already unlocked, and the weapons inventory contains the id
     if (!UnlockedWeaponIDs.Contains(weaponID) && WeaponsInventory.ContainsKey(weaponID))
     {
         UnlockedWeaponIDs.Add(weaponID);
         weaponPanel.updatePanels(UnlockedWeaponIDs);
         // Show panel to indicate there is a new weapon
         StartShowPanelCoroutine();
     }
 }
示例#3
0
    void Awake()
    {
        weaponsInventory = this.GetComponent <WeaponsInventory>();

        //Inventory Panel
        weaponsInventoryButton = GameObject.Find(weaponsInventoryButtonPath).GetComponent <Button>();
        weaponsInventoryButton.onClick.AddListener(WeaponsControls);
        WeaponsSubBar = GameObject.Find(WeaponsSBPath);

        //Weapons Inventory Panel
        WeaponsInventoryPanel = GameObject.Find(WeaponsInventoryPanelPath);
        WeaponsInventoryPanel.SetActive(false);
    }
示例#4
0
    void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
        // Using help from https://answers.unity.com/questions/1580211/when-an-object-is-dontdestroyonload-where-can-i-pu.html
        if (scene.isLoaded)
        {
            // Only look for these things in non menu indexes and non game over(game over is always the last index)
            if (scene.buildIndex > 1 && scene.buildIndex < SceneManager.sceneCountInBuildSettings - 1)
            {
                ResetDynamicDifficulty();
                levelTimer = 0;
                Instantiate(HUD);
                ingameMenu = Instantiate(ingameMenuObject);
                ingameMenu.SetActive(false);
                // Generate level by number currently 2 non game scenes
                playerController = levelGeneration.GenerateLevel(scene.buildIndex - 2, player).GetComponent <BaseFirstPersonController>();

                SetupWeaponInventory();
                // Add all enemies in the level into an array
                var enemies = GameObject.FindGameObjectsWithTag("Enemy");
                var bosses  = GameObject.FindGameObjectsWithTag("Boss");
                foreach (var enemyGameObject in enemies)
                {
                    enemiesOnLevel.Add(enemyGameObject.GetComponent <Enemy>());
                }
                foreach (var bossGameObject in bosses)
                {
                    enemiesOnLevel.Add(bossGameObject.GetComponent <Enemy>());
                }
                // Adjust enemy values
                AdjustEnemyAttributes();

                SetupUI();
                weaponPanel.switchWeaponHighlight(ActiveWeaponID);
                weaponPanel.updatePanels(UnlockedWeaponIDs);
                weaponPanel.gameObject.SetActive(false);
                // Two doors unlocked by progressing through the level
                bossEntranceDoor = GameObject.FindWithTag("BossEntranceDoor");
                levelExitDoor    = GameObject.FindWithTag("LevelExitDoor");

                Debug.Log(scene.buildIndex == previousBuildIndex);
                // If its the same level and unlcoked the boss door.
                if (unlockedBossDoor && scene.buildIndex == previousBuildIndex)
                {
                    OpenBossEntrance();
                }
                else
                {
                    unlockedBossDoor = false;
                }
                // Set the text again on the level loaidng in
                UpdateMuteText();
                SetScoreText();
                SetLivesText();
                itemProgress = 0;
                SetItemProgressText();
                updateTimeText();

                //Find the active weapon, set it to active
                var weaponManagement = GameObject.FindWithTag("WeaponManagement").GetComponent <WeaponManagement>();
                weaponManagement.ActiveWeapon = WeaponsInventory[ActiveWeaponID];
            }
            else if (scene.buildIndex == 0 || scene.buildIndex == SceneManager.sceneCountInBuildSettings - 1)
            {
                levelTimer   = 0;
                MaxHealth    = 100;
                CurrentLives = MaxLives;
                // Clear all weapons
                WeaponsInventory.Clear();
                UnlockedWeaponIDs.Clear();
                UnlockedWeaponIDs.Add(1);
                // unlock the cursor on loading the menu(if you're coming back from playing)
                Cursor.lockState = CursorLockMode.None;
                Cursor.visible   = true;
                if (scene.buildIndex == 0)
                {
                    // Get the difficulty dropdown
                    difficultySelection = GameObject.FindWithTag("DifficultySelection").GetComponent <Dropdown>();
                }
                else if (scene.buildIndex == SceneManager.sceneCountInBuildSettings - 1)
                {
                    endScreenText = GameObject.FindWithTag("EndScreenText").GetComponent <Text>();
                    if (BeatGame)
                    {
                        endScreenText.text = "Congratulations\n You beat the game";
                    }
                    else
                    {
                        endScreenText.text = "Game Over";
                    }
                }
            }

            previousBuildIndex = scene.buildIndex;
        }
    }
示例#5
0
 //Weapons
 public void AddWeaponToInventory(Weapon weapon)
 {
     WeaponsInventory.Add(weapon.WeaponID, weapon);
 }