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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
-1
Question by Itsproinc · Jul 08, 2013 at 08:35 PM · javascriptguimoney

If statement only work once?

Hello I have a little trouble with my script, can someone please help me?

Here's the thing, when my "TEST2.js" earn some value on "money1" (still lower than the price), it works.

When I press the GUI in-game it wont add the amout of "hoverForce" and decrease the amout of "money1" and "money".

But after I bought the item +1 or +5 or +10 I can just buy it non-stop untill -1 and so on but I set it >(bigger) than the price value.

I don't know how to fix this because -(negative) is smaller than 0 :) i just don't get it with the logic

 TEST.js

 static var hoverForce : int = 0;
 static var thisisjustatest : int = 0;
 
 function OnTriggerStay (other : Collider)
 {
     other.rigidbody.AddForce(Vector3.up * hoverForce, ForceMode.Acceleration);
    
 }
 
 function OnGUI(){
 
 GUI.Label (Rect (100,100,50,20), thisisjustatest.ToString(), "box");
 
 }

                          TEST2.js

 static var money1 : float = 0;
 
 function OnGUI()
     {
     if(GUI.Button(Rect(200, 100, 40, 20), "+1")){
     if(money1 > 0.9)
     {
     TEST.thisisjustatest += 1;
     TEST.hoverForce += 1;
     TEST4.money -= 1;
     audio.Play();
     }
     }
     if(GUI.Button(Rect(240, 100, 40, 20), "+5")){
     if(money1 > 4.5)
     {
     TEST.thisisjustatest += 5;
     TEST.hoverForce += 5;
     audio.Play();
     }
     }
     if(GUI.Button(Rect(280, 100, 40, 20), "+10")){
     if(money1 > 9.9)
     {
     TEST.thisisjustatest += 10;
     TEST.hoverForce += 10;
     audio.Play();
     }
     }
     if(GUI.Button(Rect(200, 130, 40, 20), "-1")){
     TEST.thisisjustatest -= 1;
     TEST.hoverForce -= 1;
     audio.Play();
     }
     if(GUI.Button(Rect(240, 130, 40, 20), "-5")){
     TEST.thisisjustatest -= 5;
     TEST.hoverForce += 5;
     audio.Play();
     }
     if(GUI.Button(Rect(280, 130, 40, 20), "-10")){
     TEST.thisisjustatest -= 10;
     TEST.hoverForce += 10;
     audio.Play();
     }
 }
                          TEST3.js

 static var timer : float = 1;
 static var addtime : float = 1;
 
 function Update(){
   timer -= Time.deltaTime;
   if (timer < 0){
   TEST3.timer += addtime;
   TEST4.money += 0.5;
   TEST2.money1 += 0.5;
 }
 }
 
 function OnGUI(){
 
 GUI.Label (Rect (100,280,100,20), timer.ToString(), "box");
 
 }

                          TEST4.js

 static var money : float = 0;
 
 function OnGUI(){
 
 GUI.Label (Rect (100,300,50,20), money.ToString(), "box");
 
 }
Comment
Add comment · Show 1
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 Jake.OConnor · Jul 09, 2013 at 08:37 PM 0
Share

I would suggest posting a better formatted question and all relevant code. There are significant missing portions of your code that may or may not be important to the problem (no way to tell without seeing them). Also, try to clear up what the question actually is.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SchecterKing · Jul 09, 2013 at 10:37 PM

Just by the title of this, I would say use a bool value.

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Temperature Script? 3 Answers

Limit on GUI Components? 0 Answers

How To Make Ammo & Realod for Gun & Spark for Gun ? 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