private void Awake() { for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { GameObject temp = Instantiate(star, new Vector3(i * 2 + 0.2f, j * 2 + 0.2f, 0), transform.rotation); BackgroundStar tempBG = temp.GetComponent <BackgroundStar>(); tempBG.speed = speedC; } } for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { GameObject temp = Instantiate(star, new Vector3(i * 2 - 0.2f, j * 2 - 0.2f, 0), transform.rotation); BackgroundStar tempBG = temp.GetComponent <BackgroundStar>(); tempBG.speed = speedM; } } for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { GameObject temp = Instantiate(star, new Vector3(i * 2, j * 2, 0), transform.rotation); BackgroundStar tempBG = temp.GetComponent <BackgroundStar>(); tempBG.speed = speedF; } } GameObject.FindGameObjectWithTag("Star").GetComponent <BackgroundStar>().PopulateSprites(); }
public bool Initialize(GameMain gameMain, out string reason) { _gameMain = gameMain; _backGroundStar = SpriteManager.GetSprite("BackgroundStar", _gameMain.Random); if (_backGroundStar == null) { reason = "Star sprite doesn't exist."; return false; } int numOfStars = (_gameMain.ScreenSize.X * _gameMain.ScreenSize.Y) / 500; _backGroundStars = new BackgroundStar[numOfStars]; List<BackgroundStar> orderedBackgroundStars = new List<BackgroundStar>(); for (int i = 0; i < numOfStars; i++) { Color color = Color.White; switch (_gameMain.Random.Next(6)) { case 0: color = Color.OrangeRed; break; case 1: color = Color.LightBlue; break; case 2: color = Color.Violet; break; case 3: color = Color.LightGreen; break; case 4: color = Color.Yellow; break; } BackgroundStar newStar = new BackgroundStar(gameMain.Random.Next(gameMain.ScreenSize.X), gameMain.Random.Next(gameMain.ScreenSize.Y), _gameMain.Random.Next(1, 20), color); orderedBackgroundStars.Add(newStar); } orderedBackgroundStars.Sort((a, b) => { return a.Layer.CompareTo(b.Layer); }); _backGroundStars = orderedBackgroundStars.ToArray(); reason = null; return true; }