void SetLevel() { if (lgo != null) { GameObject.Destroy(lgo); lgo = null; } var level = _levelNames[_currentLevel]; var subDir = $"Levels/{level}"; var goPath = $"{subDir}/Level{level}"; Debug.Log($"Instantiating {goPath}"); { var go = Resources.Load <GameObject>(goPath); if (go == null) { throw new Exception($"failed to load resource '{goPath}'"); } lgo = Instantiate(go); } Level = (AbstractLevel)lgo?.GetComponent <MonoBehaviour>(); if (Level == null) { throw new Exception($"failed to find component for level '{level}'"); } if (audioSource != null) { audioSource.Stop(); } audioSource = lgo.GetComponent <AudioSource>(); if (audioSource != null) { audioSource.Play(); } var bgcam = GameObject.Find("Background Camera").GetComponent <Camera>(); bgcam.backgroundColor = Level.clearColor; var bggo = GameObject.Find("BackgroundPlane"); bggo.GetComponent <MeshRenderer>().material = Level.backgroundMaterial; _currentLevel = ++_currentLevel % _levelNames.Length; // update current visuals: foreach (var c in Playfield.GetEnumeratorCells()) { InstantiateVisual(c); } foreach (var s in Playfield.GetEnumeratorSquares()) { // InstantiateVisual(s); } var dpv = GameObject.Find("DropPiece").GetComponent <DropPieceView>(); dpv.UpdateVisuals = true; }