- Home /
GUI help !
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;
}
}
in order for somebody to help you'd need to say why it doesn't work and what you think it's supposed to do. "it doesn't work" (probably) isn't good enough for anyone to spend their time helping you.
did you write it yourself?
at least you managed to format your code correctly: +1 for that! ;)
I just asked for an answer ... not for correction and criticises ... English isn't my native language ... So you can help me or just let me !
i don't believe that i was criticizing at all but in order to help you, it's necessary to know what's wrong.
if you can't tell me then i'll go help somebody else.
enjoy your day.
Idk where is the problem ... All I want is when I reach a certain amount of coins ... a GUI text apprears with the message "Level UP!" and after that it will dissapear after 2 seconds :D !
first you should get the habit of using debugs to spot which part of the code is not working, that would be easier for you and everyone.
second, your coroutine should be like
IEnumerator Show$$anonymous$$essage (string message, float delay) {
guiText.text = message;
guiText.enabled = true;
while(true){
yield return new WaitForSeconds(delay);
guiText.enabled = false;
yield break;
}
as gjf pointed, I do not also know what is not working. maybe your code isn't even attached to anything and does not work. something like this is expected;
"I can see the level label, but level up message does not show".
Answer by NaRango4 · Nov 28, 2014 at 01:30 PM
small bug in your code,
coins = PlayerPrefs.GetInt("Coins", 0);
should be
coins = PlayerPrefs.GetInt("Coins");
you are passing extra arguments here
remember, difference between GetInt and SetInt :)
Your answer
Follow this Question
Related Questions
Making a real coroutine 3 Answers
GUI Rect not showing on play 2 Answers
hide button 1 Answer
why cant my GUI.Label Show when i put it 1 Answer
How to hide/unhide a GUI image when character enters trigger. 1 Answer