コード例 #1
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();
     }
 }
コード例 #2
0
 public void AddToItemProgress()
 {
     itemProgress++;
     SetItemProgressText();
     Debug.Log(unlockedBossDoor);
     if (itemProgress >= RequiredItemsAmount && !unlockedBossDoor)
     {
         UnlockWeapon(UnlockedWeaponIDs.Last() + 1);
         OpenBossEntrance();
         unlockedBossDoor = true;
     }
 }
コード例 #3
0
    void Awake()
    {
        levelGeneration = GetComponent <LevelGeneration>();

        // start the game off with only 1 weapon index equal to the single shooter one
        UnlockedWeaponIDs.Add(1);
        UnlockedWeaponIDs.Add(2);
        UnlockedWeaponIDs.Add(3);
        CurrentLives = MaxLives;
        // Only for testing if starting inside a level


        // Adding the multipiers
        difficultyMultipliers.Add(DifficultyLevel.Easy, 0.7f);
        difficultyMultipliers.Add(DifficultyLevel.Medium, 1f);
        difficultyMultipliers.Add(DifficultyLevel.Hard, 1.5f);

        // Getting difficulty selection and adding a listener
        // Only do if on the start screen(This is for testing, game will always start on menu)
        if (SceneManager.GetActiveScene().buildIndex == 0)
        {
            // Get the difficulty dropdown
            difficultySelection = GameObject.FindWithTag("DifficultySelection").GetComponent <Dropdown>();
            // Using code from https://docs.unity3d.com/2018.3/Documentation/ScriptReference/UI.Dropdown-onValueChanged.html
            difficultySelection.onValueChanged.AddListener(delegate
            {
                DropdownValueChanged(difficultySelection);
            });
        }

        // Only have one instance of game management running
        if (instance != null && instance != this)
        {
            DestroyImmediate(gameObject);
            return;
        }
        instance = this;
        DontDestroyOnLoad(gameObject);
    }
コード例 #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;
        }
    }