Hello!
I’m essentially trying to get the score (# of flips) from this script:
#pragma strict
var flips = 0;
var facingUp = true;
function Update() {
if (facingUp) {
if (Vector3.Dot(Vector3.up, transform.up) < -0.75) {
facingUp = false;
flips++;
}
}
else {
if (Vector3.Dot(Vector3.up, transform.up) > 0.75) {
facingUp = true;
flips++;
}
}
Debug.Log(flips);
}
and print it on the screen during the “game over” scene, but I don’t know how to get the variable to carry over. On top of that, I’m getting an error with my text on the “game over” scene:
“Object reference not set to an instance of an object”, which appears to be due to my ToString() method in the following code:
#pragma strict
var go : pizza;
var text : UI.Text;
var printer : String;
function Awake() {
DontDestroyOnLoad (transform.gameObject);
}
function Start () {
go = GameObject.Find("pizza-small").GetComponent.<pizza>();
}
function Update () {
printer = go.flips.ToString();
text.text = "Score: " + printer;
}
I have tried to use DontDestroyOnLoad in the first script, but I assume that it doesn’t work since there’s an error with my text on the second script? I’m really unsure how to go about it, any help is appreciated. Thanks!