- Home /
Score system Level Load
Hey guys. I have a score script (attached to the player) that gives the player a point or 2 each time they beat an enemy. However, I have more than one level and when I load a new level, it resets the score. Here's the script:
using UnityEngine;
using System.Collections;
public class ScoreCount : MonoBehaviour {
public int maxScore = 15;
public int curScore = 0;
void Awake() {
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
AddjustCurrentScore(0);
}
void OnGUI() {
GUI.Box(new Rect(1075,10,90,20),"Score:" + curScore + "/" + maxScore);
}
public void AddjustCurrentScore(int adj) {
curScore += adj;
if(curScore < 0)
curScore = 0;
if(curScore > maxScore)
curScore = maxScore;
if(maxScore < 1)
maxScore = 1;
}
}
Is there a way I could have the score count save when I load a new level. Thanks!
(If post doesn't appear right, please edit)
Answer by DragonSaige · Aug 26, 2012 at 03:24 PM
Sounds confusing. If you don't manually change your score it will stay the same even after you load another level. Also , I have a look at the script where you placed your application.loadlevel();.
I haven't done that yet, but if I did, I would use this code:
ScoreCount sc = (ScoreCount)_player.GetComponent("ScoreCount"); sc.AddjustCurrentScore(+2); if(sc.curScore == 15) { Application.LoadLevel(levelindex);
I'm still not very sure why you are switching to next scene when all you want is to spawn enemies. I'd rather do
if(sc.curScore == maxScore) { level++; maxScore +=15; }
and then in enemy script multiply speed,spawnCount by level. this will make your score consistent and you won't have to go through the trouble of switching scenes. hope it helps
Okay, I finally understand what you were trying to do; Here's how: 1. $$anonymous$$ake a object, say x, that'll hold all the variables from your level 1. 2. Apply DontDestroyOnLoad() function on x. 3. Load new level, then use x to get all the values back.
Your answer
Follow this Question
Related Questions
PlayerPrefs 2 Answers
Saving score to next level? 3 Answers
Score and Level Loading 1 Answer
checkpoint level please 2 Answers