Well i did fix that i could load level 2 for my game in the script but how do i let it load level 3 after level 2 in this script? Code (CSharp): using UnityEngine; using System.Collections; public class GameManager : MonoBehaviour { public GameObject player; private GameObject currentPlayer; private GameCamera cam; private Vector3 checkpoint; public static int levelCount = 2; public static int currentLevel = 1; public static int secondLevel = 2; void Start () { cam = GetComponent<GameCamera>(); if (GameObject.FindGameObjectWithTag("Spawn")) { checkpoint = GameObject.FindGameObjectWithTag("Spawn").transform.position; } SpawnPlayer(checkpoint); } // Spawn player private void SpawnPlayer(Vector3 spawnPos) { currentPlayer = Instantiate(player,spawnPos,Quaternion.identity) as GameObject; cam.SetTarget(currentPlayer.transform); } private void Update() { if (!currentPlayer) { if (Input.GetButtonDown("Respawn")) { SpawnPlayer(checkpoint); } } } public void SetCheckpoint(Vector3 cp) { checkpoint = cp; } public void EndLevel() { if (currentLevel < levelCount) { currentLevel++; Application.LoadLevel("Level" + secondLevel); } else { Debug.Log("Game Over"); } } } Because the level 2 is int secondlevel = 2; and i added it under the endlevel? but how do i load the level 3 scene on it?
If you want to load a scene in addition to the scene already running, you need use loadleveladditive. If you want to use loadlevel, pass the Name of the level to this method.
Get the currently loaded level index with Application.loadedLevel, increase it by 1, and use Application.LoadLevel with the new value.
Well what's the exact code? is it Application.loadedlevel(1) or application.loadedlevel("level" + secondlevel); or what???? I don't know what you mean.
Honestly, that method I mentioned is so straight forward that it is nearly as good as code. And please don't be angry, coding MIGHT sometimes involve getting your own hands dirty. ;-) I strongly recommend the scripting documentation: http://docs.unity3d.com/ScriptReference/ Or more specifically the part about the Application class: http://docs.unity3d.com/ScriptReference/Application.html Teach a man to fish and so on... ;-)
Buuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuut hooooooooooooooooooooowwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
get rid of secondLevel var... you already have the functionality built in and are blinded apparently by forum watching... Code (csharp): public void EndLevel() { if (currentLevel < levelCount) { currentLevel++; ///Application.LoadLevel("Level" + secondLevel); Application.LoadLevel("Level" + currentLevel); // use the var you already set for the new level otherwise it's wasted and not needed } }
*sigh* Code (CSharp): public void EndLevel() { int nextLevel = Application.loadedLevel + 1; if (nextLevel < Application.levelCount) { Application.LoadLevel(nextLevel); } else { int i = 0; while (i < 1000) { Debug.Log("I shall be friendly to people and empower myself to learn how to code!"); i++; } } }
if it didn't load it then you have it named differently... maybe use the scene number instead of the name if you have so it doesn't require a certain naming convention to load.