/// <summary> /// Loads a new map, updates the gui and initialises animation. /// </summary> /// <param name="index">Which map to load.</param> private void LoadPreview(int index) { float x = 0; //unload current map if (p_currentMapPreview != null) { x = p_currentMapPreview.transform.position.x; //save the map position before we instantiate another map Destroy(p_currentMapPreview); } //load new map and initialise string sceneName = MemoryCard.GetScene(index); p_currentMapPreview = (GameObject)Instantiate(Resources.Load("prefab_" + sceneName)); p_currentMapPreview.transform.localScale = new Vector3(1, 1, 1) * 0.5f; p_currentMapPreview.transform.Rotate(new Vector3(1, 0, 0), -50, Space.World); //spawn the new map on the left or right side of the screen dependent on last mapanimation if (x > 0) { p_currentMapPreview.transform.position = p_mapLeftPosition; p_currentMapPreview.transform.Translate(2, 0, 0, Space.World); //translate it a little bit so the if statement for loading a new map wont be triggered } else { p_currentMapPreview.transform.position = p_mapRightPosition; p_currentMapPreview.transform.Translate(-2, 0, 0, Space.World); } p_mapGoToThisPosition = p_mapMiddlePosition; //new destination for the map is the center //update the gui, highscore float bestTime = MemoryCard.LoadHighScore().timeInSeconds; if (bestTime != 0) { p_textString = "level " + (index + 1) + " / " + MemoryCard.levelSize + "\nbest time " + bestTime.ToString("f2") + "s"; } else { p_textString = "level " + (index + 1) + " / " + MemoryCard.levelSize + "\nbest time --.--s"; } }
// Start is called before the first frame update private void Start() { p_lookAtPosition = new GameObject(); p_lookAtPosition.transform.Translate(new Vector3(0, 1, 0)); p_levelControl = GameObject.FindWithTag("LevelControl"); p_levelControl.GetComponent <LevelTilt>().m_playerHasControl = false; p_timeInSeconds = 0; //prepare camera start animation for loading into the scene m_camera.transform.Translate(new Vector3(m_startCamera, 0, 0)); m_camera.GetComponent <CameraController>().m_lookAt = p_lookAtPosition.transform; p_cameraSmoothTime = m_camera.GetComponent <CameraController>().m_smoothTime; m_camera.GetComponent <CameraController>().m_smoothTime = p_cameraSmoothTime * 2; //load highscore and show it p_bestTimeInSeconds = MemoryCard.LoadHighScore().timeInSeconds; if (p_bestTimeInSeconds != 0) { m_bestTime.text = p_bestTimeInSeconds.ToString("f2"); } m_currentTime.text = p_timeInSeconds.ToString("f2"); StartCoroutine(WaitForASecond()); }