Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-2
Question by Louis-LCM · Nov 28, 2014 at 10:55 AM · guicoroutineshow

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;
     }
 }
Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gjf · Nov 28, 2014 at 09:30 AM 0
Share

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! ;)

avatar image Louis-LCM · Nov 28, 2014 at 09:46 AM 0
Share

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 !

avatar image gjf · Nov 28, 2014 at 09:54 AM 0
Share

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.

avatar image Louis-LCM · Nov 28, 2014 at 09:57 AM 0
Share

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 !

avatar image koray1396 · Nov 28, 2014 at 12:13 PM 0
Share

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".

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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 :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges