private void Update() { _timeSinceThrow += Time.deltaTime; if (_timeSinceThrow >= 4f / _intensity) { FallingRockParticle rock = Instantiate(_fallingRockBehaviour, new Vector3(Random.Range(_playerPosition.Value.x - _cameraWidth, _playerPosition.Value.x + _cameraWidth), _playerPosition.Value.y + _mainCamera.orthographicSize + 2f, 0f), Quaternion.identity); rock.Initialize((int)(_playerPosition.Value.y / 100f)); _timeSinceThrow = 0f; } }
private IEnumerator Raycast() { _timeToDeactivation = 60f; while (true) { if (Random.Range(0f, 1f) < _probabilityOfFalling) { RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 5f, _playerLayer); #if UNITY_EDITOR Debug.DrawRay(transform.position, Vector3.down * 5f, Color.red); #endif if (hit.collider != null) { if (hit.collider.GetComponent <PlayerController>() != null) { Grid grid = GetComponentInParent <Grid>(); Vector3Int gridPos = grid.WorldToCell(transform.position); Destroy(gameObject); _overrideTiles.Raise(new OverrideTilesEA( new Dictionary <Vector2Int, TileType>() { { (Vector2Int)gridPos, _overriddenTileType } })); FallingRockParticle frp = Instantiate(_fallingRockParticlePrefab, transform.position, Quaternion.identity); frp.Initialize((int)Mathf.Abs(gridPos.y / 20f)); } } _timeToDeactivation -= _interval; if (_timeToDeactivation <= 0f) { enabled = false; break; } } yield return(new WaitForSeconds(_interval)); } }