Exemple #1
0
 void Update()
 {
     if (characterSelector.GetCharacterActive())                                                            //checks if the character is active
     {
         playerHealthManager = characterSelector.GetCharacterObject().GetComponent <PlayerHealthManager>(); //get the instantiated (or active) player's PlayerHealthManager script
         maxHealth           = playerHealthManager.GetMaxHealth();                                          //sets a variable to teh value of the character's max health
         currentHealth       = playerHealthManager.GetCurrentHealth();                                      //sets a variable to teh value of the character's max health
         healthBar.maxValue  = maxHealth;
         healthBar.value     = currentHealth;
         //healthText.text = "HP: " + ((currentHealth / maxHealth) * 100).ToString() + "%"; //sets the health text to the player's current health as a percentage
         healthText.text = "HP: " + (currentHealth.ToString() + " / " + maxHealth.ToString()); //sets the health text to the player's current health over max health //changed to avoid decimal percentages (since the Warrior and Archer's health isn't 100)
     }
 }
 void Update()
 {
     characterSelector = FindObjectOfType <CharacterSelector>();
     audioManager      = FindObjectOfType <AudioManager>();
     try                                                                                                        //hastily done because a non-gamebreaking error was being thrown once the player is killed
     {
         if (characterSelector.GetCharacterActive())                                                            //checks if the character is active
         {
             playerHealthManager = characterSelector.GetCharacterObject().GetComponent <PlayerHealthManager>(); //gets the current player instance's health manager
             maxHealth           = playerHealthManager.GetMaxHealth();
             currentHealth       = playerHealthManager.GetCurrentHealth();
         }
     }
     catch
     {
         //pass
     }
 }
Exemple #3
0
    public void Update()
    {
        currentHealth = playerHealthManager.GetCurrentHealth();

        if (hurtEnemy.GetSuccessfulHit())                    //checks if the hit was successful after triggering siphon
        {
            if (currentHealth + healthToReturn >= maxHealth) //if returning health would make the players health greater than 100, set the current health to 100
            {
                playerHealthManager.SetCurrentHealth(maxHealth);
            }
            else
            {
                playerHealthManager.SetCurrentHealth(currentHealth + healthToReturn);
            }
            hurtEnemy.SetSuccessfulHit();
            isSiphonActive = false;
        }
    }
    IEnumerator SwapLevelTimer()
    {
        if (!titleScreen)
        {
            try //chose to do this because an error that wasn't affecting the flow of the game was coming up
            {
                playerController.ResetMoveSpeedAndAttackTime();
            }
            catch
            {
                //pass
            }
            characterSelector.GetCharacterObject().SetActive(false);
        }

        yield return(new WaitForSeconds(swapLevelTime));

        if (selectRandomScene)                                                        //if the selectRandomScene boolean is active, then the gameobject the script is attached to wants to randomly load levels from a list
        {
            if (scenesListLength > 0 && (scenesListLength != chosenScenesListLength)) //if the array doesn't have any levels to select from, the code will not be run to avoid any errors
            {
                int  randomSceneNum;
                bool available = false;
                while (!available)                                          //if the specific random number that was chosen isn't in the list of levels (that holds the build indexes), then keep randomly choosing
                {
                    randomSceneNum = Random.Range(1, scenesListLength + 1); //set to start at one since the Title Screen's index is 0 //had to add a +1 since the starting point was changed

                    if (chosenScenesListLength > 0)
                    {
                        if (CheckChosenNum(randomSceneNum))
                        {
                            levelTransitionManager.AddChosenScene(randomSceneNum);
                            levelTransitionManager.SetLevelIndex(randomSceneNum);
                            available = true;
                        }
                    }
                    else
                    {
                        levelTransitionManager.AddChosenScene(randomSceneNum);
                        levelTransitionManager.SetLevelIndex(randomSceneNum);
                        available = true;
                    }
                }
                if (!titleScreen && returnPlayerHealth)
                {
                    playerHealthManager.SetCurrentHealth(playerHealthManager.GetCurrentHealth() + 50); //returns the player's health to the specified value if the fillPlayerHealth boolean is selected
                    //playerHealthManager.SetCurrentHealth(playerHealthManager.GetMaxHealth()); //returns the player's health to full if the fillPlayerHealth boolean is selected
                }
                levelTransitionManager.FadeToLevel(); //loads the randomly selected level
            }
            else //will load the VictoryScreen if all levels are complete
            {
                gameOver = true;
                characterSelector.TurnOffCanvas();
                levelTransitionManager.SetLevelIndex(SceneManager.sceneCountInBuildSettings - 2); //the penultimate level index is the Victory Screen but needs to be -2 because the index starts at 1
                levelTransitionManager.FadeToLevel();
            }
        }
        else
        {
            if (levelToLoad == "GameOverScreen") //string reference is slightly dangerous, but works fine
            {
                gameOver = true;
                characterSelector.TurnOffCanvas();
            }
            SceneManager.LoadScene(levelToLoad); //loads a selected scene since random selection is not the desired functionality
        }
    }