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
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 …
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() …
In every script that calls the static globals you need to define the scene script like this.
//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>();