public static void UpdateLevel() { m_List = LevelSerializer.SavedGames[LevelSerializer.PlayerName]; LevelSerializer.SaveEntry[] tempL = m_List.ToArray(); int tempI = -1; for (int i = 0; i < tempL.Length; i++) { if (tempL[i].Name == Application.loadedLevelName) { tempI = i; } } if (tempI != -1) { if (m_List[tempI].Name == Application.loadedLevelName) { if (m_SpawnPosition != -1) { PlayerSpawn tempG = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerSpawn>(); //.SpawnPlayer(m_SpawnPosition); if (tempG.m_Positions.Length > m_SpawnPosition) { tempG.SpawnPlayer(m_SpawnPosition); } } //Debug.Log("Kommer hit " + m_SpawnPosition); LevelSerializer.LoadNow(m_List[tempI].Data); } } }
public static void RestartLevel() { Destroy(player); GlobalSettings.levelStarting = true; var currentScene = SceneManager.GetActiveScene().name; var currentLevel = currentScene.Substring(5, 3); GlobalSettings.xCoordinate = 0f; // Just go back to the earth start if dying on the moon or sun if (GlobalSettings.onMoon || GlobalSettings.onSun) { GlobalSettings.onMoon = false; GlobalSettings.onSun = false; SceneManager.LoadScene("Level" + currentLevel + "_earth"); return; } // Spawn at the appropriate location if dying on earth Vector3 spawnLocation = new Vector3(); if (spawnEmptyObject != null) { spawnLocation = new Vector3(spawnEmptyObject.transform.position.x, spawnEmptyObject.transform.position.y); } else { if (GameObject.Find("SpawnStart") != null) { spawnEmptyObject = GameObject.Find("SpawnStart"); } else { spawnEmptyObject = GameObject.Find("SpawnDefault"); } spawnLocation = new Vector3(spawnEmptyObject.transform.position.x, spawnEmptyObject.transform.position.y); } // Respawn the player if (spawnLocation == Vector3.zero) { PlayerSpawn.SpawnPlayer((GameObject)Resources.Load("Player"), true); } else { PlayerSpawn.SpawnPlayer((GameObject)Resources.Load("Player"), true, spawnLocation); } GlobalSettings.isDead = false; PauseScreenScript.pauseScreen.SetActive(false); Time.timeScale = 1f; }
public IEnumerator GenerateMap() { generationInProgress = true; // Increment the seed of the random mapGenerator.mapGenerationJob.random = new Unity.Mathematics.Random(seed + levelNumber); // Prepare base array for the jobs NativeArray <int> mapResult = new NativeArray <int>(parameters.mapSizeX * parameters.mapSizeY, Allocator.TempJob); mapGenerator.mapGenerationJob.result = mapResult; // Start the map generation job JobHandle jobHandle = mapGenerator.mapGenerationJob.Schedule(); // Wait until map generation job is completed yield return(new WaitUntil(() => jobHandle.IsCompleted)); // Ensure that the job is completed jobHandle.Complete(); // Give the simple map to the grid update job grid.gridUpdateJob.cells = mapGenerator.mapGenerationJob.result; NativeArray <int> nodeResult = new NativeArray <int>((parameters.mapSizeX - 1) * (parameters.mapSizeY - 1), Allocator.TempJob); grid.gridUpdateJob.result = nodeResult; // Start the update of the grid jobHandle = grid.gridUpdateJob.Schedule(); // Wait until the grid update job is completed yield return(new WaitUntil(() => jobHandle.IsCompleted)); // Ensure that the job is completed jobHandle.Complete(); // Translate the map result to actual cells mapGenerator.TranslateNativeArrayToCellBiArray(); // Translate the node result to the actual nodes grid.TranslateGridUpdateJobResult(); // Draw the map mapDrawer.DrawMap(mapGenerator.cells); // Prepare the level number for the next generation levelNumber++; generationInProgress = false; // Spawn the player playerSpawn.SpawnPlayer(); actualDayDuration = 0; // Start the level gameState = GameState.INGAMEDAY; }
void Restart() { won = false; dead = false; paused = false; winMenu.gameObject.SetActive(false); PlayerSpawn p = (PlayerSpawn)FindObjectOfType(typeof(PlayerSpawn)); p.SpawnPlayer(); }
public void ResetGame() { gameOverMenuIsOn = false; PlayerSpawner.SpawnPlayer(); GameOverMessage.SetActive(false); foreach (Key key in keyDoorManager.takenKeys) { key.gameObject.SetActive(true); } foreach (Door door in keyDoorManager.openDoors) { door.CloseDoor(); } keyDoorManager.FlushLists(); }
private void KillPlayer(GameObject player) { Destroy(player); Vector3 spawnLocation = new Vector3(); if (spawnEmptyObject != null) { spawnLocation = new Vector3(spawnEmptyObject.transform.position.x, spawnEmptyObject.transform.position.y); } // Respawn the player if (spawnLocation == Vector3.zero) { PlayerSpawn.SpawnPlayer((GameObject)Resources.Load("Player"), true); } else { PlayerSpawn.SpawnPlayer((GameObject)Resources.Load("Player"), true, spawnLocation); } }
// Start is called before the first frame update void Start() { // The canvas and its child objects are prefabs // Unity seems to be a bit wonky when dragging prefabs into prefabs (stuff not already in the scene, maybe a reference issue...) // This is an attempt to get the specific button into the current menu object so non-mouse navigation will work without clicking somewhere first. var pauseCanvas = GameObject.Find("CanvasPauseScreen"); var resumeButton = pauseCanvas.transform.Find("PanelPause/ButtonResume"); EventSystem eventSystem = EventSystem.current; eventSystem.firstSelectedGameObject = resumeButton.gameObject; var currentScene = SceneManager.GetActiveScene().name; var currentArea = currentScene.Substring(9); if (currentArea != "sun") { GlobalSettings.onSun = false; } else { GlobalSettings.sunIsOut = false; GlobalSettings.onSun = true; } // If the level is just starting, don't start in the air... if (GlobalSettings.levelStarting) { var startObject = GameObject.Find("SpawnStart"); if (startObject == null) { startObject = GameObject.Find("SpawnDefault"); } if (GameObject.Find("Player") == null) { PlayerSpawn.SpawnPlayer(Player, false, startObject.transform.position); } } else // Otherwise, spawn in the air, because the player will be arriving in the scene from jumping off the other scene... { // UnityEngine.Debug.Log("Spawning player at scene start"); PlayerSpawn.SpawnPlayer(Player, false); // Spawn the indicator to show the entry point to the scene float indicatorYPosition = Camera.main.ViewportToWorldPoint(new Vector3(0f, 0f, 0f)).y; // If we're on earth, put the arrow at the top instead of the bottom, and flip the dumb thing over if (!GlobalSettings.onMoon) { indicatorYPosition = Camera.main.ViewportToWorldPoint(new Vector3(1f, 1f, 1f)).y; entryArrow = Instantiate((GameObject)Resources.Load("EntryArrow"), new Vector3(GlobalSettings.xCoordinate, indicatorYPosition), Quaternion.identity); Vector3 objectScale = entryArrow.transform.localScale; objectScale *= -1; entryArrow.transform.localScale = objectScale; } entryArrow = Instantiate((GameObject)Resources.Load("EntryArrow"), new Vector3(GlobalSettings.xCoordinate, indicatorYPosition), Quaternion.identity); } }