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
0
Question by shafferchance · Jul 06, 2014 at 11:41 PM · buttonboolean

My first if statement is going through but then the gui button doesn't work afterwards. Can anyone explain or solve it please(bool broke)?

 using UnityEngine;
 using System.Collections;
 
 public class shipStats : MonoBehaviour {
     
     public TwoDController twoD;
     public bullet bull;
     public saveLoad sL;
     public int damage = 0;
     public int hull = 0;
     public int gun = 0;
     public int aExp;
     public int level = 0;
     private bool useMoney = true;
     private bool useStuff = false;
     private bool maxLevel = false;
     public bool broke = false;
     public bool toUps;
     public string[] hullLevel = {"Iriduim Steel composite-$0","Meteoric Iron-$1000","Arudium-$2000"};
     public string[] gunType = {"Gunpowder-0","Incendiary-$500","Engery-$1000"};
     private float currency;
     
     // Use this for initialization
     void Start () {
         currency = twoD.money;
         aExp += twoD.eExp;
     }
     
     // Update is called once per frame
     void Update () {
         if(useMoney && useStuff){
             useMoney = !useMoney;
             useStuff = !useStuff;
         }
         switch(level){
         case 0:
             if(aExp >= 0)
                 level += 1;
             break;
         case 1:
             if(aExp >= 200)
                 level += 1;
             break;
         case 2:
             if(aExp >= 500)
                 level += 1;
             break;
         case 3:
             if(aExp >= 1000)
                 level += 1;
             break;
         case 4:
             maxLevel = true;
             break;
         }
     }
     
     void OnGUI () {
         GUI.TextField(new Rect(400f,0f,100f,50f),"Balance " + currency + ".");
         if(!toUps){
             if(GUI.Button(new Rect(Screen.width/4f,Screen.height/4f,100f,100f),"Upgrade")){
                 Debug.Log("Button clicked");
                 toUps = true;
             }
         }
         if(toUps) {
             GUILayout.BeginArea(new Rect(Screen.width/4f + 50f,Screen.height/2f,1024f,1024f));
             GUILayout.BeginVertical();
             useMoney = GUILayout.Toggle(useMoney,"Use Money for purchasing");
             useStuff = GUILayout.Toggle(useStuff,"Use stuff to upgarde");
             hull = GUILayout.Toolbar(hull,hullLevel,GUILayout.Width (700f));
             gun = GUILayout.Toolbar(gun,gunType,GUILayout.Width(700f));
             GUILayout.EndVertical();
             GUILayout.EndArea();
             if(GUI.Button(new Rect(0f,0f,100f,50f),"back")){
                 sL.saveData ();
                 toUps = !toUps;
             }
             if(maxLevel)
                 GUI.Label(new Rect(Screen.width/3f,Screen.height/2f,500f,200f),"Congrats you have gotten to the maxuim level at this time.");
         }
         if(GUI.changed){
             switch(hull){
             case 0:
                 if(currency >= 0f)
                     twoD.health = 1000;
                 else 
                     broke = true;
                 break;
             case 1:
                 if(currency >= 1000f)
                     twoD.health = 2000;
                 else
                     broke = true;
                 break;
             case 2:
                 if(currency >= 2000f)
                     twoD.health = 3000;
                 else
                     broke = true;
                 break;
             }
             switch(gun){
             case 0:
                 if(currency >= 0f)
                     bull.damage = 30;
                 else
                     broke = true;
                 break;
             case 1:
                 if(currency >= 500f)
                     bull.damage = 100;
                 else
                     broke = true;
                 break;
             case 2:
                 if(currency >= 1000f)
                     bull.damage = 200;
                 else
                     broke = true;
                 break;
             }
         }
         if(broke){
             if(GUI.Button(new Rect(Screen.width/2,Screen.height/2,200f,50f),"You can't afford this.")){
                 broke = !broke;
             }    
         }
     }
 }
 
Comment
Add comment · Show 2
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 Kiwasi · Jul 06, 2014 at 11:55 PM 0
Share

Can you be more specific about what your are expecting to happen, and what actually is happening. As written your code is very difficult to read, and its difficult to figure out what you are trying to do.

avatar image shafferchance · Jul 15, 2014 at 07:03 PM 0
Share

I figured it out.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Controlling multiple booleans 1 Answer

Changing Color of Material with Bool and Unity UI 1 Answer

Why is door opening so fast with boolean condition? 0 Answers

Making button activate update with boolean 1 Answer

How to change boolean value once on KeyDown 0 Answers


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