void SetNewBackground() { var _lastBackgroundGroup = _backgroundGroup.Last(); var _lastBackgroundGroupPostionX = _lastBackgroundGroup.First().transform.position.x; var _nextBackground = _currentTheme.BackgroundGroup[_currentTheme.NextAvailableBackgroundIndex]; _backgroundGroup.Add(_nextBackground); _currentTheme.IncreaseBackgroundIndex(); _widthLastBackground = _lastBackgroundGroup[0].GetComponent <SpriteRenderer>().sprite.bounds.size.x; foreach (var element in _nextBackground) { element.transform.position = new Vector3(_lastBackgroundGroupPostionX + _widthLastBackground, element.transform.position.y, element.transform.position.z); element.SetActive(true); } }
void InitializeBackgrounds() { _currentTheme = _styleDictionary[_currentStyleName]; _backgroundGroup = _currentTheme.BackgroundGroup; _foregroundGroup = _currentTheme.ForegroundGroup; //First background panel is to the left of the player; float firstBackgroundPositionX = -_currentTheme.Width; //group of elements that make one complete background image for (int i = 0; i < _backgroundGroup.Count; i++) { //layers in one background image foreach (var group in _backgroundGroup[i]) { group.SetActive(true); group.transform.position = new Vector3( firstBackgroundPositionX + _currentTheme.Width * i, group.transform.position.y, group.transform.position.z); } _currentTheme.IncreaseBackgroundIndex(); } for (int i = 0; i < _foregroundGroup.Count; i++) { //layers in one foreground image foreach (var group in _foregroundGroup[i]) { group.SetActive(true); group.transform.position = new Vector3( firstBackgroundPositionX + _currentTheme.Width * i, group.transform.position.y, group.transform.position.z); } _currentTheme.IncreaseForegroundIndex(); } _widthLastBackground = _widthLastForeground = _currentTheme.Width; }