Example #1
0
    async private void ConsumeAfterWait()
    {
        await Task.Delay(TimeSpan.FromSeconds(m_EatMushroomsEvery));

        m_MushroomCounter = Math.Max(m_MushroomCounter - m_MushroomConsumptionPerMeal, 0);
        OnMushroomCountChanged?.Invoke(m_DesiredMushroomCount, m_MushroomCounter);
        ConsumeAfterWait();
    }
Example #2
0
    public void AddMushroom(GameObject _harvestedMushroom)
    {
        OnMushroomCountChanged?.Invoke(m_DesiredMushroomCount, ++m_MushroomCounter);

        if (_harvestedMushroom != null)
        {
            m_Claimed.Remove(_harvestedMushroom);

            if (Application.isEditor)
            {
                DestroyImmediate(_harvestedMushroom);
            }
            else
            {
                Destroy(_harvestedMushroom);
            }
        }

        foreach (var spawnedMushroomPair in m_SpawnedMushrooms)
        {
            if (spawnedMushroomPair.Value != null)
            {
                continue;
            }

            int countForTransform = m_RespawnQueue.Count(_entry => _entry.Item2 == spawnedMushroomPair.Key);
            if (countForTransform != 0)
            {
                continue;
            }

            float randomRespawnTimer = Time.time + UnityEngine.Random.Range(m_MinMaxRespawnTimerInSeonds.x, m_MinMaxRespawnTimerInSeonds.y);

            m_RespawnQueue.Add(new Tuple <float, Transform>(randomRespawnTimer, spawnedMushroomPair.Key));
        }
    }