Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Script GUI

Discussion in 'Scripting' started by 787gabriel777, Jul 28, 2015.

  1. 787gabriel777

    787gabriel777

    Joined:
    Jul 20, 2015
    Posts:
    65
    hello
    i need a little help
    a dont now what is wrong
    but that script doesnt function!
    when i click in my skill button
    the sistem doesnt open my other buton!
    help me!
    (THE GU MP and HP doesnt apears!)
    whats the problem?
    Code (JavaScript):
    1. function OnGUI()
    2.                    {
    3.                     if (GUI.Button(Rect(inbw, inbh, size, size1), "Inventory"))
    4.                     {
    5.                             if (GUI.Button(Rect(inbw, inbh, size, size1), "Force")){
    6.                                     if(skill>=cost){
    7.                                     Attributes.force+-1;
    8.                                     timer+=1
    9.                                     }
    10.                            
    11.                             }
    12.                             if (GUI.Button(Rect(inbw, inbh, size, size1), "mp")){
    13.                             }
    14.                             if (GUI.Button(Rect(inbw, inbh, size, size1), "hp")){
    15.                             }
    16.                    
    17.                      
    18.                     }
    19.  
    20.                  }
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Forget about legacy GUI. Use the UI instead.
     
  3. garrido86

    garrido86

    Joined:
    Dec 17, 2013
    Posts:
    233
    You need to use a bool.

    Code (JavaScript):
    1. bool _showInventory;
    2.  
    3. function OnGUI() {
    4.     if (GUI.Button(Rect(inbw, inbh, size, size1), "Inventory"))
    5.         _showInventory = !_showInventory;
    6.    
    7.     if (_showInventory) {
    8.         if (GUI.Button(Rect(inbw, inbh, size, size1), "Force")) {
    9.             if (skill >= cost) {
    10.                 Attributes.force + -1;
    11.                 timer += 1
    12.             }
    13.  
    14.         }
    15.         if (GUI.Button(Rect(inbw, inbh, size, size1), "mp")) {}
    16.         if (GUI.Button(Rect(inbw, inbh, size, size1), "hp")) {}
    17.     }
     
    787gabriel777 likes this.
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  5. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Oh man I'm still using Legacy... I hate learning new systems lol I had the same problem with Mecanim... Plus it involves remaking the ENTIRE UI for a game. But the new UI is probably easier to use (and looks a whole lot better o_O ) If I didn't have to remake a whole game system I'd probably learn it...
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I'd still suggest it, even for an existing project. Its that much of an improvement.

    You can kind of mix and match, but it doesn't sort very well.
     
  7. 787gabriel777

    787gabriel777

    Joined:
    Jul 20, 2015
    Posts:
    65
    ok thanks
    now the code is ok! thanks!
    Code (JavaScript):
    1. #pragma strict
    2. static var skill:int;
    3. var cost:int;
    4. var timer:int;
    5. var _showInventory : boolean = false;
    6.  
    7. function Start () {
    8. skill=0;
    9. cost=3;
    10. timer=0;
    11. }
    12. function Update () {
    13. if(timer >= 5){
    14. cost+=1;
    15. timer=0;
    16. }
    17. }
    18. function OnGUI() {
    19.     if (GUI.Button(Rect(100,100,60,50), "Inventory"))
    20.         _showInventory = !_showInventory;
    21.  
    22.     if (_showInventory) {
    23.         if (GUI.Button(Rect(100,150,60,50), "Force")) {
    24.             if (skill >= cost) {
    25.                 Attributes.force +=1;
    26.                 timer += 1;
    27.             }
    28.         }
    29.         if (GUI.Button(Rect(100,200,60,50), "mp")) {}
    30.         if (GUI.Button(Rect(100,260,60,50), "hp")) {}
    31.     }
    32.     }
     
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Can you describe what "does not function" means. Be specific, don't make this a guessing game. For UI stuff screenshots also help.

    And pick up a book on basic grammar and spelling.
     
  9. 787gabriel777

    787gabriel777

    Joined:
    Jul 20, 2015
    Posts:
    65
    LOL i am a guy 14 years old and i am braziliam;-;
     
  10. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    All the more reason why the book is necessary, but your biggest problem isn't language, it's the lack of effort. Every single post you make looks like you found some random thing on the internet and copy/pasted it without knowing how a single piece of it actually works.

    Go find a book on C# or Javascript or something. Find a book on English while you're at it- being from a non-English-speaking country means you have to work harder to make yourself understood in an international setting, it isn't a crutch that people are going to tiptoe around. Look through DOZENS of tutorials on Unity's website, for everything. The fact that you're focusing on the old UI style says to me that you're looking everywhere BUT Unity's website for information. Debug.Log EVERYTHING, and don't come to the support forum until if/when you have a valid, measurable problem that you can point at and not just "somehow it isn't working- I've tried nothing to get it to work since I don't want to have to learn a programming language or how Unity works. Fix it for me!".

    You've had literally a DOZEN threads up on here in the past 4 days alone, and we are NOT here to teach you everything about the program from scratch. I'm not going to be responding to any of your threads for a few weeks, minimum.

    Here you go: http://docs.unity3d.com/ScriptReference/Debug.Log.html
     
    Kiwasi likes this.
  11. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I'm pretty sure you code doesn't care about you age or the fact that you are Brazilian.

    If you believe otherwise there is nothing I can do to help.