void CheckDeath()
 {
     // checks bear health
     if (enemyHealth.GetCurrentValue() == 0f)
     {
         AudioSource.PlayClipAtPoint(deathSound, transform.position);
         if (GetComponent <ZombieAI>() != null)
         {
             GetComponent <ZombieAI>().status = EnemyState.Die;
             Destroy(gameObject, 2f);
         }
         else
         {
             GetComponent <EnemyStatesNav>().currentState = EnemyStatesNav.FSMStates.Dead;
         }
     }
 }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        StaminaCooldown = false;

        developerMode = FindObjectOfType <WorldSettings>().developerMode;
        worldSettings = FindObjectOfType <WorldSettings>();

        // Initializes player stats.
        playerHealth = new StatController(100f, 0f, statUpdateFreq, 5f * 60f, false);
        playerHealth.SetMessages(healthMessages);
        messageOrder[0]   = new Tuple <int, string, float>(0, healthMessages[0], 0);
        statTexts[0].text = healthMessages[0];

        playerHunger = new StatController(100f, 0f, statUpdateFreq, 5f * 60f, true);
        playerHunger.SetMessages(hungerMessages);
        messageOrder[1]   = new Tuple <int, string, float>(1, hungerMessages[0], 0);
        statTexts[1].text = hungerMessages[0];

        playerRadiation = new StatController(0f, 100f);
        playerRadiation.SetMessages(radiationMessages);
        messageOrder[2]   = new Tuple <int, string, float>(2, radiationMessages[0], 0);
        statTexts[2].text = radiationMessages[0];

        playerStamina = new StatController(100f, 0f, statUpdateFreq, 20f, false);
        playerStamina.SetMessages(staminaMessages);
        messageOrder[3]   = new Tuple <int, string, float>(3, staminaMessages[0], 0);
        statTexts[3].text = staminaMessages[0];


        if (developerMode)
        {
            healthBar.SetMaxValue(playerHealth.GetCurrentValue());
            hungerBar.SetMaxValue(playerHunger.GetCurrentValue());
            radiationBar.SetMaxValue(playerRadiation.GetMaxValue());
            radiationBar.SetValue(playerRadiation.GetCurrentValue()); // Makes sure radiation starts at 0;
            staminaBar.SetMaxValue(playerStamina.GetCurrentValue());
        }

        radZone = GameObject.FindGameObjectWithTag("RadiationZone").GetComponentInChildren <RadiatePlayer>();

        startTime = Time.time;
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        if (!worldSettings.IsGameOver())
        {
            if (developerMode)
            {
                // Uncomment for testing purposes. Delete after demonstration.
                if (Input.GetKeyDown(KeyCode.Alpha6))
                {
                    ChangePlayerHealth(-5f);
                }
                if (Input.GetKeyDown(KeyCode.Alpha7))
                {
                    ChangePlayerHealth(5f);
                }
                if (Input.GetKeyDown(KeyCode.Y))
                {
                    ChangePlayerHunger(-5f);
                }
                if (Input.GetKeyDown(KeyCode.U))
                {
                    ChangePlayerHunger(5f);
                }
                if (Input.GetKeyDown(KeyCode.N))
                {
                    ChangePlayerRadiation(-5f);
                }
                if (Input.GetKeyDown(KeyCode.M))
                {
                    ChangePlayerRadiation(5f);
                }
                if (Input.GetKeyDown(KeyCode.Alpha8))
                {
                    ChangePlayerStamina(-5f);
                }
                if (Input.GetKeyDown(KeyCode.Alpha9))
                {
                    ChangePlayerStamina(5f);
                }
            }

            float health    = playerHealth.GetCurrentValue();
            float hunger    = playerHunger.GetCurrentValue();
            float radiation = playerRadiation.GetCurrentValue();

            UpdateMessageTexts();
            UpdateMessageAlphas(Time.deltaTime);

            // Checks if the player is dead.
            if (health == 0 || hunger == 0 || radiation == playerRadiation.GetMaxValue())
            {
                GetComponent <PlayerController>().PlayerDies();
            }

            if (playerStamina.GetCurrentValue() == 0)
            {
                StaminaCooldown = true;
            }
            else if (StaminaCooldown && playerStamina.GetCurrentValue() >= playerStamina.GetMaxValue() / 5)
            {
                // If the player just got the ability to use stamina again, change the stamina message from the
                // "stamina gone" message to the "stamina low" message.
                playerStamina.MessageChanged = false;
                messageOrder[3] = Tuple.Create(messageOrder[3].Item1, staminaMessages[3], messageOrder[3].Item3);
                UpdateStatText(3);
                StaminaCooldown = false;
            }
        }
    }