Exemplo n.º 1
0
    private void Awake()
    {
        baseFirstPersonController = GetComponent <BaseFirstPersonController>();
        baseForwardSpeed          = baseFirstPersonController.forwardSpeed;

        BaseCharacterController.OnSetCrouch += Crouch;
    }
Exemplo n.º 2
0
    public IEnumerator WaitStun()
    {
        isStunned = true;
        OnSetStunned.Invoke(isStunned);

        stunPivot.SetActive(true);
        stunPivot.transform.localPosition += transform.up * 0.5f;
        Vector3 raisedStunPos = stunPivot.transform.localPosition;

        stunPivot.transform.DOLocalMove(initialStunPivotPos, 0.2f);

        // Small wait to let player get pushed back
        yield return(new WaitForSeconds(0.2f));

        BaseFirstPersonController fpController = GetComponent <BaseFirstPersonController>();

        fpController.GetComponent <BaseFirstPersonController>().pause = true;
        yield return(new WaitForSeconds(stunDuration));

        fpController.GetComponent <BaseFirstPersonController>().pause = false;

        stunPivot.transform.DOLocalMove(raisedStunPos, 0.2f).OnComplete(() => {
            stunPivot.SetActive(false);
        });
        isStunned = false;
        OnSetStunned.Invoke(isStunned);
    }
Exemplo n.º 3
0
 private void Start()
 {
     PlayerDash.OnStopDash += CheckSlow;
     controller             = GetComponent <BaseFirstPersonController>();
     initialForwardSpeed    = controller.forwardSpeed;
     initialBackwardSpeed   = controller.backwardSpeed;
     initialStrafeSpeed     = controller.strafeSpeed;
 }
Exemplo n.º 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;
        }
    }