Hello Unity Answers,
I’m trying to make a simple gameover screen with the score shown to the player.
I have created a new scene and copied everything from the main scene into it and repositioned the score text but the score doesn’t update.
All ideas & suggestions welcome.
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Question10 : MonoBehaviour {
private Rect windowRect = new Rect (500, 100, 400, 200); //Window size
public bool question10;
private int count;
public Text countText;
private bool showTimer = true;
private float Timer = 10f;
void start()
{
count = 0;
SetCountText ();
}
void FixedUpdate(){
if (showTimer == true) {
Timer -= Time.deltaTime;
}
if (Timer <= 0f) {
showTimer = false;
Timer = 10f;
Destroy (this.gameObject);
Application.LoadLevel (Application.loadedLevel);
}
}
void OnGUI()
{
windowRect = GUI.Window (0, windowRect, WindowFunction, "Ebola Quiz Island"); //window on screen
}
void WindowFunction (int windowID)
{
// Draw any Controls inside the window here
GUI.Label(new Rect (30, 25, 400, 50), " How many proven treatments are there for Ebola?"); // Question
if (GUI.Button (new Rect (20, 100, 100, 30), "None"))
{
Destroy (this.gameObject);
count = count + 10;
SetCountText ();
Application.LoadLevel("Gameover");
}
if (GUI.Button (new Rect (280, 100, 100, 30), "One"))
{
Destroy (this.gameObject);
Application.LoadLevel("Gameover");
}
if (GUI.Button (new Rect (20, 150, 100, 30), "Two"))
{
Destroy (this.gameObject);
Application.LoadLevel("Gameover");
}
if (GUI.Button (new Rect (280, 150, 100, 30), "Three"))
{
Destroy (this.gameObject);
Application.LoadLevel("Gameover");
}
if (showTimer == true)
{
GUI.Label (new Rect (175, 50, 200, 50), "Timer: " + Timer.ToString ("F0"));
}
}
void SetCountText()
{
ValuesHolder.answersCount++;
countText.text = "Score: " + ValuesHolder.answersCount.ToString();
}
}
using UnityEngine;
using System.Collections;
internal class ValuesHolder
{
internal static int answersCount = 0;
}
**When the player clicks the None the scoreboard scene ( Application.LoadLevel(“Gameover”) will be loaded but the score won’t be updated?
**