示例#1
0
    IEnumerator IEConstantDamageByTime(float damage)                      //  weapon like lighting bolt can produce constant damage by time
    {
        int framesToExplosion = 10;
        int currentFrame = 0;

        while (true)                                                      // only Method interuptConstantDamage can  interrupt this, or break
        {
            currentFrame++;

            if (currentFrame == framesToExplosion)                        // it prevents to call random explosion everyframe
            {
                ExplosionController.instance.RandomExplosionEffect(transform.position);
                currentFrame = 0;
            }

            IEConstandDamageByTimeAdditional();                           // method with additional option, can be implement in  inhereted classes
            currentHealth -= damage;
            healthBar.UpdateBar(currentHealth, maxHealth);

            if (currentHealth <= 0)
            {
                DestroyEffect();
                break;                                                    // exit the loop
            }

            yield return null;
        }
    }
    IEnumerator IncreaseWithTime()
    {
        isStaminaFull = false;

        while (!isStaminaFull)                                          // go to while when current will be full
        {
            currentStamina += Time.deltaTime * staminaIncreaseSpeed;    // increase stamina with time

            if (currentStamina > maxStamina)                            // if current stamina value is greatest than max
            {
                ReadyToUse();                                           // invoke animation, sounds that shows that stamina is full
                isStaminaFull = true;                                   // stop increase stamina, stop while loop
            }

            staminaBar.UpdateBar(currentStamina, maxStamina);           // update stamina bar on screen

            yield return(null);                                         // refresh screen
        }
    }
示例#3
0
    IEnumerator DecreaseShieldTime()
    {
        while (currentShieldTime > 0)
        {
            shieldBar.UpdateBar(currentShieldTime, maxShieldTime);              // update bar's appierrience
            currentShieldTime -= Time.deltaTime;                                // decrease shield's  value
            yield return(null);                                                 // wait frame
        }

        shieldBar.HideBar();                                                    // Hide bar when his value == 0
        GetComponent <PlayerController>().ActiveShield(false);                  // disactive shield in PlayerController script, that he will susceptible by damage
        playerShield.SetActive(false);                                          // turn off shield if time left;
    }
    void CheckFuel()
    {
        currentFuel -= Time.deltaTime;                                              // decrease fuel
        fuelBar.UpdateBar(currentFuel, maxFuel);                                    // update visual fuel bar on screen

        if (currentFuel < 0)                                                        // if fuel is over 
        {
            isFuelOver = true;                                                      // set flag fuel is over

            float noFuelHorizontal = horizontalMove / factorMoveWithoutFuel;        // set noFuel horizontal speed
            float noFuelVertical = verticalMove / factorMoveWithoutFuel;            // set noFuel vertical speed

            StartCoroutine(LerpMovementChange(noFuelHorizontal, noFuelVertical));   // decrease player speed to speed without fuel
        }
    }
    private VisualBar staminaBar;                           // reference to staminaBar that controll bar on screen


    void OnEnable()
    {
        currentStamina = maxStamina;                                                    // set current stamina value to max

        GameMaster.instance.staminaController = this;                                   // set in GameMaster reference to stamina Controller

        staminaBar = GameObject.FindWithTag("StaminaBar").GetComponent <VisualBar>();   // get reference to stamina bar that controlls bar on screen
        staminaBar.UpdateBar(currentStamina, maxStamina);                               // update this value on bar

        audioSource = staminaBar.gameObject.GetComponent <AudioSource>();               // get reference to audioSource in staminaBar object

        if (isIncreaseWithTime)                                                         // if IncreaseWithTime is On
        {
            StartCoroutine(IncreaseWithTime());                                         // Run coroutine that will increase stamina with time
        }
        if (isIncreaseWithKill)                                                         // if - because can be both option active Time and kill
        {
            GameMaster.instance.StaminaByKill = true;                                   // set in GameMaster bollen to true, because GameMaster will invoke method IncreaseWithKilling when player kill the enemy
        }
        ReadyToUse();                                                                   // invoke animation, sounds that shows that stamina is full
    }
    void OnEnable()
    {
        currentStamina = maxStamina;                                                    // set current stamina value to max

        GameMaster.instance.staminaController = this;                                   // set in GameMaster reference to stamina Controller

        staminaBar = GameObject.FindWithTag("StaminaBar").GetComponent<VisualBar>();    // get reference to stamina bar that controlls bar on screen
        staminaBar.UpdateBar(currentStamina, maxStamina);                               // update this value on bar

        audioSource = staminaBar.gameObject.GetComponent<AudioSource>();                // get reference to audioSource in staminaBar object

        if (isIncreaseWithTime)                                                         // if IncreaseWithTime is On
            StartCoroutine(IncreaseWithTime());                                         // Run coroutine that will increase stamina with time

        if (isIncreaseWithKill)                                                         // if - because can be both option active Time and kill
            GameMaster.instance.StaminaByKill = true;                                   // set in GameMaster bollen to true, because GameMaster will invoke method IncreaseWithKilling when player kill the enemy

        ReadyToUse();                                                                   // invoke animation, sounds that shows that stamina is full
    }