private void Update()
    {
        // If the target exists...
        if (target != null)
        {
            // Move towards the target.
            agent.destination = target.transform.position;
            // Occasionally attempt to deal damage towards the target.
            float timePassed = ts.GetTimePassed();
            timerBetweenAttacks -= timePassed;
            while (timerBetweenAttacks <= 0f)
            {
                timerBetweenAttacks += timeBetweenAttacks;

                float distance = Vector3.Distance(transform.position, target.transform.position);
                // If the enemy is close enough to the target to deal damage...
                if (distance < damageDistance)
                {
                    // Damage the target.
                    target.Damage(damage, Health.Type.Impact, true);
                    // Play sound.
                    soundArray.PlayRandomSound();
                }
            }
        }
    }
    private void Update()
    {
        float timePassed = ts.GetTimePassed();

        if (timerBetweenWaves > 0f)
        {
            timerBetweenWaves -= timePassed;
            if (timerBetweenWaves <= 0f)
            {
                StartWave();
            }
        }
        else
        {
            // Manages the enemy spawning loop during waves.
            if (enemiesSpawnedThisWave < enemiesPerWave)
            {
                timerBetweenEnemies -= timePassed;
                while (timerBetweenEnemies <= 0f)
                {
                    timerBetweenEnemies += timeBetweenEnemies;
                    SpawnEnemy();
                    // Once all of the enemies have been spawned, end the wave.
                    if (enemiesSpawnedThisWave == enemiesPerWave)
                    {
                        EndWave();
                    }
                }
            }
        }
    }
    private void Update()
    {
        float timePassed = ts.GetTimePassed();

        hungerTimer -= timePassed;
        while (hungerTimer <= 0f)
        {
            hungerTimer += hungerTime;
            health.Damage(1, Health.Type.Hunger);
        }
    }
 private void Update()
 {
     if (attackTimer > 0f)
     {
         float timePassed = ts.GetTimePassed();
         attackTimer -= timePassed;
         if (attackTimer <= 0f)
         {
             AttackStateDisable();
         }
     }
 }
示例#5
0
    private void Update()
    {
        if (!isGrown)
        {
            float timePassed = ts.GetTimePassed();
            float increase   = rate * timePassed;
            stalks.transform.localScale += Vector3.up * yScaleFactor * increase;
            stalks.transform.position   += (Vector3.up * increase) / 2;
            currentScale += increase;
            if (currentScale >= maxScale)
            {
                FinishGrowing();
            }
#if PLANTSTATUS_USEMETER
            meter.SetCurrentValue(currentScale);
#endif
        }
    }
    private void Update()
    {
        float timePassed = ts.GetTimePassed();

        if (!canEat)
        {
            eatCooldownTimer -= timePassed;
            if (eatCooldownTimer < 0f)
            {
                eatCooldownTimer = eatCooldownTime;
                canEat           = true;
            }
        }
        // If the villager is heading towards food...
        if (destinationIsFood)
        {
            // GET TO THE FOOD ROY
            agent.destination = cropTarget.transform.position;
            // If the villager is close enough to the crop...
            if ((GetDestinationDistance() < cropEatDistance) && canEat)
            {
                // Eat a bit of the crop.
                cropTarget.DecreaseHealth();
                // Restore health.
                compHealth.Heal(1, Health.Type.Hunger);
                // Temporarily prevent the villager from eating another crop.
                canEat = false;
            }
        }
        // If the villager is NOT heading towards food, head towards other things.
        else
        {
            // If the villager is targeting the shrine...
            if (destinationIsShrine)
            {
                agent.destination = shrine.transform.position;
                // If the villager is within shrine charging distance...
                if (GetDestinationDistance() < shrineChargeDistance)
                {
                    // Increase the idle time.
                    timeIdled += timePassed;
                    // If the villager has idled at the shrine for long enough...
                    if (timeIdled > shrineIdleTime)
                    {
                        // Reward faith points.
                        shrine.IncreasePoints(compVillagerStatus.faithAmount, transform.position);
                        // Reset the idle time and stop targeting the shrine.
                        timeIdled           = 0f;
                        destinationIsShrine = false;
                        // Check if the villager wants food.
                        CheckIfWantsCrop();
                    }
                }
            }
            // If the villager is targeting the house...
            else
            {
                agent.destination = houseTransform.position;
                // If the villager is close enough to the house destination to be considered idling...
                if (GetDestinationDistance() < houseDestinationDistance)
                {
                    // Increase the idle time.
                    timeIdled += timePassed;
                    // If the villager has idled at the house for long enough...
                    if (timeIdled > houseIdleTime)
                    {
                        // Reset the idle time and start heading to the shrine.
                        timeIdled           = 0f;
                        destinationIsShrine = true;
                        // Check if the villager wants food.
                        CheckIfWantsCrop();
                    }
                }
            }
        }
    }