Code (csharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Score : MonoBehaviour { public Text scoreText; public int score; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { scoreText.text = "Clicks" + score; if (Input.GetMouseButtonDown(0)) { score++; } } } how can i reference the score in another scene. if i want to have the score of clicks shown in the next scene how could i do this? thanks for any help
@matstacy Please use code tags... you can edit your message with edit button. You can use a script in GameObject that you set to DontDestroyOnLoad - this way you can have this object + its script persist even if scene loads. You can use PlayerPrefs to save and load the value. You can use any other available C# or Unity serialization method to save and load your data.
So for me to reference or show the score on another scene do i just use the same script in new scene and it will show me the same score? or do i need to make a new object/script that will have the variable of scoretext? im still really confused sorry if im being a pain with easy Questions
You can use a global static variable to keep track of your score. Some people will say not to do this, and they are right is some circumstances, but it works fine for a simple game. I have a SCENE object that runs a SR_Scene script. That script declares global static variables .... Code (CSharp): public static class Global { public static int GameDifficulty = 3; //0 = easy, 1 normal, 2 difficult, 3 insane public static bool FriendlyFire = false; public static int CurrentLevel = 0; //level player is on, to track/increase difficulty public static bool LevelCleared = true; } Later in the scene script you can access those value like this for example to increase the CurrentLevel .... Global.CurrentLevel++; Other scripts will have to access the Scene script to get or set these variables. Example for a script on an enemy spaceship OnEnable() ... Code (CSharp): if (SR_Scene.Global.GameDifficulty > 0) { //they get faster MaxSpeed += SR_Scene.Global.GameDifficulty; if(MaxSpeed > SR_Scene.Global.MaxPlayerSpeed) { MaxSpeed = SR_Scene.Global.MaxPlayerSpeed; } //and stronger MaxHull += + SR_Scene.Global.GameDifficulty; if (MaxHull > SR_Scene.Global.MaxHull) { MaxHull = SR_Scene.Global.MaxHull; } CurrentHull = MaxHull; //and shoot faster GunCoolRate += SR_Scene.Global.GameDifficulty * 0.01f; if(GunCoolRate > MaxGunCoolRate) { GunCoolRate = MaxGunCoolRate; } } In every script that calls the static globals you need to define the scene script like this. Code (CSharp): //declare up top of the enemy script private GameObject SceneController; private SR_Scene SceneScript; //define in the awake function of enemy script SceneController = GameObject.FindWithTag("GameController"); SceneScript = SceneController.GetComponent<SR_Scene>();