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");
}