Hi, im very new with unity, I have a problem with my games…
example problem: I have score 200 on my old stage, but when I load stage score back to 0 but if I hit coin score jump from 0 to 300 (1 coin get score 100), what I want is score in load stage same as current old stage score 200 not 0.
heres my script Skor.js its atached on empty game object
static var score : int = 0;
var guiScore : GUIText;
static var teks = false;
function LateUpdate()
{
if(teks)
{
guiScore.text = "Score: " + score;
teks = false;
}
}
here is my koin.js score atached to coin object
var rotateSpeed : float = 150.0; //Your speed
var efek : Transform;
function Update () //The update function will trigger your object to make it rotate
{
transform.Rotate (rotateSpeed * Time.deltaTime, 0.0, 0.0); //It never stops rotating.
}
function OnTriggerEnter( hit : Collider )
{
if(hit.gameObject.tag == "worm")
{
Skor.score += 100;
Skor.teks = true;
var exp = Instantiate(efek, gameObject.transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
I alredy heard about playerperfs but I dont know how to applied it to my script as im very new with unity and javascript.
You can go with a static var score : int. It will store the score until the game exits. If you need to get the score back when you play the game again after you close it, you will need to look at PlayerPrefs. What you need is this:
Skor.js
static var score : int = 0;
var guiScore : GUIText;
static var teks = false;
function Start() {
//This will fix your dilemma
guiScore.text = "Score: " + score;
}
function LateUpdate()
{
if(teks)
{
guiScore.text = "Score: " + score;
teks = false;
}
}
In your example, after you reset your scene, the GUItext will jump from 0 to 300. So, just update the score in Start() to make sure that the GUItext display the latest score when the scene start.