|
Post by thehobliks on Aug 26, 2014 11:04:21 GMT
turns out the feature i requested isn't going to work but here goes....
at the top of each level it displays the score of the current level using a world variable named "Score". each level has it's own high score variable. Level 1 - "001", Level 2 - "002", etc. i'm trying to set it to where for example if you complete level 1 then it'll set the "001" to the same value that "Score" has if it's greater. i have it set this way so it can unlock the next level if the score is over a certain number and also display all of the scores on a level select screen. this is the code i have and of course i'm getting errors because i'm terrible at coding. any help would be appreciated. thank you.
using UnityEngine;
using System.Collections;
public class greaterthan : MonoBehaviour {
// Use this for initialization
void Start () {
var variable = WorldVariableTracker.GetWorldVariable("001");
var variable2 = WorldVariableTracker.GetWorldVariable("Score");
}
// Update is called once per frame
void Update () {
if(variable2 > variable)
{
variable = variable2;
}
}
}
|
|
|
Post by DarkTonic Dev on Aug 26, 2014 23:24:55 GMT
First, it's a waste of CPU to update every single frame. There's a WorldVariableListener class we can use so that we only update the High Score when normal Score updates. Here's a subclass of WorldVariableListener for the Score variable.
public class ScoreListener : WorldVariableListener { public override void UpdateValue(int newValue) { base.UpdateValue(newValue);
if (WorldVariableTracker.IsInitializing) { return; }
var highScoreVariable = WorldVariableTracker.GetWorldVariable("HighScore"); highScoreVariable.SetIntValueIfAllowed(newValue); } }
However, this will take an update of CGK and I'll submit that this week.
|
|