void CreateWorldSegments() { float x = world_PaddingRange.y; float padding = world_PaddingRange.y; while (x <= worldWidth - padding) { GenericTrash worldSegment = GetNewWorldSegment(); //worldSegment.CachedTransform.parent = CachedTransform; float x_pos = GetXPositionFor(worldSegment, x); x = GetNextXPositionFor(worldSegment, x_pos) + GetPadding(); x_pos += tleft.position.x; float y = tdown.position.y + worldSegment.GetHeight() * 0.5f; Vector2 pos = new Vector2(x_pos, y); worldSegment.CachedTransform.position = pos; } }
void CreateForegroundElements() { float x = 0f; while (x <= worldWidth) { if (UnityEngine.Random.value <= chanceToSpawnForegroundElement) { float x_pos = x + UnityEngine.Random.Range(foreground_HorizontalDistribution.x, foreground_HorizontalDistribution.y); if (x_pos > worldWidth) { x = worldWidth + 1f; break; } GenericTrash foreground = GetNewForegroundElement(); x = GetNextXPositionFor(foreground, x_pos); x_pos += tleft.position.x; Vector2 pos = new Vector2(x_pos, tdown.position.y + foreground.GetHeight() * 0.5f); foreground.CachedTransform.position = pos; } else { x += UnityEngine.Random.Range(background_HorizontalDistribution.x, background_HorizontalDistribution.y); } } }
void CreateSky() { float y = 0f; while (y <= worldHeight) { float x = 0f; float y_height = 0f; while (x <= worldWidth) { GenericTrash sky = GetNewSky(); y_height = sky.GetHeight(); float x_pos = GetXPositionFor(sky, x); x = GetNextXPositionFor(sky, x_pos); x_pos += tleft.position.x; Vector2 pos = new Vector2(x_pos, y + tdown.position.y); sky.CachedTransform.position = pos; } y += y_height; } }
GenericTrash GetRandomEntry(GenericTrash[] trash) { GenericTrash t = trash[UnityEngine.Random.Range(0, trash.Length)]; GenericTrash t_o = GameObject.Instantiate(t) as GenericTrash; //t_o.CachedTransform.parent = CachedTransform; return(t_o); }
void CreateBackgroundElements() { float y = backgroundBeginHeight; while (y <= worldHeight) { float x = 0f; float y_height = 0f; while (x <= worldWidth) { if (UnityEngine.Random.value <= chanceToSpawnBackgroundElement) { float x_pos = x + UnityEngine.Random.Range(background_HorizontalDistribution.x, background_HorizontalDistribution.y); if (x_pos > worldWidth) { x = worldWidth + 1f; break; } GenericTrash background = GetNewBackgroundElement(); x = GetNextXPositionFor(background, x_pos); x_pos += tleft.position.x; Vector2 pos = new Vector2(x_pos, y + tdown.position.y); background.CachedTransform.position = pos; } else { x += UnityEngine.Random.Range(background_HorizontalDistribution.x, background_HorizontalDistribution.y); } } y += UnityEngine.Random.Range(background_VerticalDistribution.x, background_VerticalDistribution.y); } }