HI All,
I am having a little trouble with updating the score from level_1 to level_2,
My aim is, once max level points have been reached on level_1 (750) then level_2 loads and the score carries over to level_2(750),
The problem is, when i gain 750 in level_1, level_2 loads fine the 750 points are shown and once the level starts it automatically gains 60 points so the application.loadlevel should stop once i have gone passed 750, as soon as level_2 loads the new score should be 810, it works but still level_2 keeps loading over and over as if i still have 750 points.
My question is how can i stop level_2 from loading over and over again?
here is my script, any ideas?
public class LevelManager : MonoBehaviour {
public LevelManager levelManager;
public int score;
public int currentLevel
public int Score=30;
private PlayerController player;
// Use this for initialization
void Start () {
player = FindObjectOfType<PlayerController>();
if (Application.loadedLevelName == "Level_1") {
score = 0;
saveScores();
} else {
score = getSavedScores();
}
}
// Update is called once per frame
void Update ()
{
saveScores();
changeLevel();
}
public void changeLevel()
{
if (score >= 750 && currentLevel == 1)
{
saveScores();
currentLevel++;
Application.LoadLevel("Level_2");
}
if(Application.loadedLevelName == "Level_2")
{
getSavedScores();
}
}
//possible if the save functionality intreacts with this
public void saveScores()
{
if (score >= 750)
{
// setting the score
PlayerPrefs.SetInt("Score", score);
}
}
public int getSavedScores()
{
int tempScore = PlayerPrefs.GetInt("Score");
return tempScore;
}
public int getScore()
{
return score;
}
public void AddPoints(int points)
{
score += points;
}
void OnGUI()
{
GUILayout.Label(score.ToString());
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.name == "Player")
{
Application.LoadLevel(0); //this is on death completely restart game
}
}
}