- Home /
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");
}
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.
Answer by SchecterKing · Jul 09, 2013 at 10:37 PM
Just by the title of this, I would say use a bool value.
Your answer
Follow this Question
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