public bool AddRuns() { Run run = null; Run lastRun; var gameObject = PoolGenerator.Get.GetRandomObject(ObjectType.RUN); if (gameObject) { run = gameObject.GetComponent <Run>(); } if (!run) { Debug.LogError("Error add a run", this); return(false); } lastRun = mRuns[mRuns.Count - 1]; run.SetTransform(lastRun.Next); mRuns.Add(run); foreach (var rail in run.Rails) { bool find = false; foreach (var globalRail in mRails) { if (globalRail.Index == rail.Key) { globalRail.AddRail(rail.Value); find = true; break; } } if (!find) { Rail newRail = new Rail(); newRail.Index = rail.Key; newRail.AddRail(rail.Value); mRails.Add(newRail); } } return(true); }
void CreateFirstRun() { Run firstRun; firstRun = GameObject.Instantiate(Resources.Load(START_RUN, typeof(Run))) as Run; if (firstRun == null) { Debug.LogError(START_RUN + " doest exist or instantiate failed"); Destroy(this.gameObject); } mRuns.Add(firstRun); mActualRun = firstRun; foreach (var rail in firstRun.Rails) { Rail newRail = new Rail(); newRail.Index = rail.Key; newRail.AddRail(rail.Value); mRails.Add(newRail); } }