Hi guys … This script was suposed to show me a “Level UP!” message when a certain amount of coins was reached … But idk why it don’t works … can any1 help me ?
Here is my script :
using UnityEngine;
using System.Collections;
public class LevelPop : MonoBehaviour {
private int coins = 0;
public GUISkin levelPopSkin;
// Use this for initialization
void Start () {
coins = PlayerPrefs.GetInt("Coins", 0);
}
// Update is called once per frame
void Update () {
}
void FixedUpdate () {
PlayerPrefs.SetInt("Coins",coins);
}
void OnGUI()
{
DisplayLevel ();
}
void DisplayLevel()
{
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity,new Vector3(Screen.width / 480.0f, Screen.height / 320.0f, 1));
GUI.skin = levelPopSkin;
Rect coinIconRect = new Rect(200, 150, 32, 32);
//LEVEL SHOW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
string skillLevel = " ";
if(coins >= 7500){
StartCoroutine(ShowMessage("LEVEL UP !", 2));
}
else if(coins >= 6900){
StartCoroutine(ShowMessage("LEVEL UP !", 2));
}
else if(coins >= 5600){
StartCoroutine(ShowMessage("LEVEL UP !", 2));
}
else if(coins >= 4500){
StartCoroutine(ShowMessage("LEVEL UP !", 2));
}
else if(coins >= 2300){
StartCoroutine(ShowMessage("LEVEL UP !", 2));
}
else if(coins >= 1600){
StartCoroutine(ShowMessage("LEVEL UP !", 2));
}
else if(coins >= 800){
StartCoroutine(ShowMessage("LEVEL UP !", 2));
}
else if(coins >= 400){
StartCoroutine(ShowMessage("LEVEL UP !", 2));
}
else if(coins >= 200){
StartCoroutine(ShowMessage("LEVEL UP !", 2));
}
else if(coins >= 100){
StartCoroutine(ShowMessage("LEVEL UP !", 2));
}
else if(coins >= 0){
StartCoroutine(ShowMessage("LEVEL UP !", 2));
}
Rect labelRect = new Rect(coinIconRect.xMax, coinIconRect.y, 60, 32);
GUI.Label(labelRect, skillLevel);
}
IEnumerator ShowMessage (string message, float delay) {
guiText.text = message;
guiText.enabled = true;
yield return new WaitForSeconds(delay);
guiText.enabled = false;
}
}