So I want to display a message at the Game Over screen. Example, If the player scores less than five points then show this message. If they score more than 5 but less than 10 show this message, else if they score more than 10 but less than 20 show this message and so on… This is my code. I get no errors so its working fine… But it only shows the lowest score. Ive tried multiple ways of recoding. None with an error, yet still only shows the lowest score. I think it may be becuase my correct score script and wrong score script call on the score value . and as you see in the show message script im calling on the score wich is pulling from both right and wrong answer scripts which is a problem. I dont really want to have to re write the scoreing just to show a message… Any help is appreciated.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Score_Message : MonoBehaviour {
public static int score;
public Font MyFont;
Text text;
void Start()
{
text = GetComponent<Text> ();
}
void OnGUI()
{
GUI.skin.font = MyFont;
if (score >= 30)
GUI.Label (new Rect (250, 400, 500, 150), "<color=white><size=30>We Bow In Your Presence!</size></color>");
else if (score <= 29 && score > 20)
GUI.Label (new Rect (250, 400, 500, 150), "<color=white><size=30>You Can See Into The Future. What Can You See?</size></color>");
else if (score <= 19 && score > 10)
GUI.Label (new Rect (250, 400, 500, 150), "<color=white><size=30>You Have The Eyes Of A Scout. Keep Your Eyes Open!</size></color>");
else if (score <= 9 && score > 5)
GUI.Label (new Rect (250, 400, 500, 150), "<color=white><size=30>You Have The Eyes Of A Mole Rat. Need Some Glasses?</size></color>");
else if (score <= 4)
GUI.Label (new Rect (250, 400, 500, 150), "<color=white><size=30>You're Not Even Trying.. Are You?</size></color>");
}
}
The Right Score Script
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Score : MonoBehaviour
{
public static int score;
Text text;
void Start()
{
text = GetComponent<Text> ();
score = 0;
score = PlayerPrefs.GetInt ("CurrentScore");
}
void Update()
{
if (score < 0)
score = 0;
text.text = "" + score;
}
public static void AddPoints (int pointsToAdd)
{
score += pointsToAdd;
PlayerPrefs.SetInt ("CurrentScore", score);
}
public static void Reset()
{
PlayerPrefs.SetInt ("CurrentScore", score);
score = 0;
}
}
And The Wrong Score Script.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Score_Wrong : MonoBehaviour
{
public static int score;
Text text;
void Start()
{
text = GetComponent<Text> ();
score = 0;
score = PlayerPrefs.GetInt ("CurrenttScore");
}
void Update()
{
if (score < 0)
score = 0;
text.text = "" + score;
}
//public void onClick(){
// if (score == 4)
// Application.LoadLevel ("Game_Over");
// text.text = "" + score;
//}
public static void AddPoints (int pointsToAdd)
{
score += pointsToAdd;
PlayerPrefs.SetInt ("CurrenttScore", score);
}
public static void Reset()
{
PlayerPrefs.SetInt ("CurrenttScore", score);
score = 0;
}
}
The Score Sytems that calls on the scores to be set in text. Both are the same with different add point names to not have reoccurring names in both scripts and to divide the two for right and wrong scoring.
using UnityEngine;
using System.Collections;
public class Score_System : MonoBehaviour {
public int pointsToAdd;
// Use this for initialization
public void onClick () {
Score.AddPoints(pointsToAdd);
}
// Update is called once per frame
void Update () {
}
}