Пример #1
0
    /// <summary>
    /// Spawn a trap after its waiting delay
    /// </summary>
    /// <param name="_trapToSpawn">Trap to spawn</param>
    /// <param name="_waitingDelay">Delay to wait</param>
    /// <returns></returns>
    private IEnumerator SpawnTrap(GameObject _trapToSpawn)
    {
        if (GameUpdater.Instance.IsStoped())
        {
            yield return(new WaitForSeconds(GameUpdater.Instance.m_TickEvent));

            StartCoroutine(SpawnTrap(_trapToSpawn));
            yield break;
        }
        Trap  _tmpTrap = _trapToSpawn.GetComponent <Trap>();
        float _delay   = _tmpTrap.m_SpawningTick * GameUpdater.Instance.m_TickEvent * m_statesCoefficient[m_currentStateIndex];

        yield return(new WaitForSeconds(_delay));

        Vector2Int _spawningPos = _tmpTrap.GetSpawningPosition();

        if (_spawningPos == null)
        {
            Debug.LogWarning($"There is no free space to spawn a {_trapToSpawn.name} on the grid");
            yield break;
        }
        Trap _trap = Instantiate(_trapToSpawn, GameData.Instance.m_TileManager.TilePositionToWorldPosition(_spawningPos), Quaternion.identity).GetComponent <Trap>();

        _trap.m_GridPosition = _spawningPos;
        GameData.Instance.m_TileManager.GetTile(_spawningPos).m_Walkable = false;
        if (GameData.Instance.m_TileManager.GetEmptyTiles().Count == 0)
        {
            yield break;
        }
        StartCoroutine(SpawnTrap(_trapToSpawn));
        yield break;
    }