need help with score system i got working with transfer score from one scene to another but score counting from 0 in second scene how to count first scene score with second score?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class ScoreManager : MonoBehaviour {
public int score;
public Text taskuText;
// Use this for initialization
void Start()
{
PlayerPrefs.GetInt("CurrentScore", score);
//taskuText.text = " HighScore: " + PlayerPrefs.GetInt("CurrentScore"); // uncomment this for start game with highScore.
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.Space))
{
getScore();
taskuText.text = "" + score;
}
}
public void highScore(){
///taskuText.text= " highScore: " + PlayerPrefs.GetInt("CurrentScore");
PlayerPrefs.SetInt("CurrentScore", score);
SceneManager.LoadScene("score2");
}
public void getScore()
{
score++;
PlayerPrefs.SetInt("CurrentScore", score);
}
}
and this is second script for second scene.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class score2 : MonoBehaviour {
public ScoreManager highScore;
public Text taskuText;
private int taskai2;
// Use this for initialization
void Start () {
highScore = FindObjectOfType<ScoreManager>();
taskuText.text = ""+ PlayerPrefs.GetInt("CurrentScore");
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.UpArrow))
{
taskai2++;
PlayerPrefs.SetInt("CurrentScore",taskai2);
taskuText.text = taskai2.ToString();
}
}
}
Comment