- Home /
Boolean function doesn't work anymore
Hello everyone
Maybe the Title of this question doesn't match 100% but i didnt find a better way to explain it because my problem is that i have this script
#pragma strict
var BG : Texture2D;
var skin3 : GUISkin;
var skin5 : GUISkin;
var Hover : GUIStyleState;
var shadow : Texture2D;
static var inGame = false;
var transformation = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);
private var menu = true;
private var options = false;
private var credits = false;
private var Coinshop = false;
var BG2 : Texture2D;
static var myVolume : float;
function Start()
{
myVolume = PlayerPrefs.GetFloat("Volume");
}
function OnGUI ()
{
GUI.skin = skin3;
if(menu == true)
{
GUI.DrawTexture(Rect(Screen.width - Screen.width, Screen.height - Screen.height, Screen.width, Screen.height), BG);
GUI.DrawTexture(Rect(Screen.width / 2 - 600, Screen.height - Screen.height, 1200, 600), shadow);
if(GUI.Button(Rect(Screen.width / 2.65, Screen.height / 2 + Screen.height / 8, 200, 70), "Play"))
{
Application.LoadLevel(1);
}
if(GUI.Button(Rect(Screen.width - 300, 100, 150, 70), "Exit"))
{
Application.Quit();
}
if(GUI.Button(Rect(Screen.width / 3.3, Screen.height / 4 + Screen.height / 3.7, 270, 70), "Settings"))
{
menu = false;
options = true;
credits = false;
Coinshop = false;
}
if(GUI.Button(Rect(Screen.width / 3.3, Screen.height /2 + Screen.height / 4, 270, 70), "Credits"))
{
menu = false;
options = false;
credits = true;
Coinshop = false;
}
if(GUI.Button(Rect(Screen.width / 1.2, Screen.height / 4 + Screen.height / 3.7, 370, 70), "Coin Shop"))
{
menu = false;
options = false;
credits = false;
Coinshop = true;
}
}
if(options == true)
{
if(Input.GetKeyDown(KeyCode.Escape))
{
var menu = true;
var options = false;
var credits = false;
var Coinshop = false;
}
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), BG2);
GUI.Label(Rect(Screen.width / 2 - 155, Screen.height / 15, 310, 70), "Settings");
GUI.skin = skin5;
GUI.Label(Rect(Screen.width / 2 - 85, Screen.height / 5 - 50 , 170, 70), "Volume");
myVolume = GUI.HorizontalSlider (Rect (Screen.width / 2 - 300, Screen.height / 5, 600, 70), myVolume, 0.0, 1.0);
}
if(Coinshop == true)
{
GUI.skin = skin3;
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), BG2);
GUI.Label(Rect(Screen.width / 2 - 250, Screen.height / 15, 500, 70), "Coin Shop");
GUI.skin = skin5;
GUI.Label(Rect(Screen.width / 2 + 300, Screen.height / 3.5 + 5, 250, 70), "Coins: " + CoinMaster.Coins);
GUI.Label(Rect(Screen.width / 2 + 300, Screen.height / 3, 500, 70), "Flashlight Range: " + PlayerPrefs.GetFloat("Range"));
if(GUI.Button(Rect(Screen.width / 2 - 250, Screen.height / 3, 500, 70), "Flashlight Range") && CoinMaster.Coins >= 1 && lightTransporter.myRange <= 50)
{
lightTransporter.myRange += 1;
CoinMaster.Coins -= 1;
}
GUI.Label(Rect(Screen.width / 2 + 300, Screen.height / 3 + 100, 500, 70), "Flashlight Intensity: " + PlayerPrefs.GetFloat("Intensity"));
if(GUI.Button(Rect(Screen.width / 2 - 250, Screen.height / 3 + 100, 500, 70), "Flashlight Intensity") && CoinMaster.Coins >= 1 && lightTransporter.myIntensity <= 2)
{
lightTransporter.myIntensity += 0.1;
CoinMaster.Coins -= 1;
}
GUI.Label(Rect(Screen.width / 2 + 300, Screen.height / 3 + 200, 500, 70), "Flashlight Angle: " + PlayerPrefs.GetFloat("Angle"));
if(GUI.Button(Rect(Screen.width / 2 - 250, Screen.height / 3 +200, 500, 70), "Flashlight Angle") && CoinMaster.Coins >= 1 && lightTransporter.myAngle <= 50)
{
lightTransporter.myIntensity += 0.1;
CoinMaster.Coins -= 1;
}
GUI.Label(Rect(Screen.width / 2 +300, Screen.height / 3 + 300, 500, 70), "Flashlight Life: " + PlayerPrefs.GetFloat("Drainspeed"));
if(GUI.Button(Rect(Screen.width / 2 - 250, Screen.height / 3 + 300, 500, 70), "Flashlight life") && CoinMaster.Coins >= 1 && Flashlight.drainSpeed >= 0.1)
{
CoinMaster.Coins -= 1;
Flashlight.drainSpeed -= 0.1;
}
if(GUI.Button(Rect(Screen.width / 2 -50, Screen.height / 2 + Screen.height / 2.8, 100, 70), "Back"))
{
menu = true;
options = false;
credits = false;
Coinshop = false;
}
if(Input.GetKeyDown(KeyCode.Escape))
{
menu = true;
options = false;
credits = false;
Coinshop = false;
}
}
if(credits == true)
{
if(Input.GetKeyDown(KeyCode.Escape))
{
credits = false;
options = false;
menu = true;
Coinshop = false;
}
}
}
function Update()
{
PlayerPrefs.SetFloat("Volume", myVolume);
}
And All Button work except the CoinShop doesnt work in the inspector you can see that it actually marks as true when i press the button but it doesnt call up the CoinShop. Thanks in advance and sorry for the confusion skullbeats1
Is lightTransporter, Coin$$anonymous$$aster and Flashlight static classes, there are ZERO references other than usage of these variables.
Answer by crodriguez · Oct 11, 2014 at 01:47 AM
By any chance do you also have Coinshop as a class? Because if so, it might be confusing it with that. So instead of writing:
private var Coinshop = false;
Change the name to:
private var coinShop = false;
Answer by Redeemer86 · Oct 09, 2014 at 06:52 AM
Ok, try this ... Wherever you are reassigning Boolean values in your code. Set all the false booleans first and at the end set the true Boolean. Like if menu = false, options = true! credits = false, coinshop = false... Change the ordering of the statements so put the statements assigning false value first and the statement assigning true statement last. Do this throughout where you have blocks setting thee four booleans accordingly. Remember to order with the true valued assignment only after setting the false ones in that block/ condition... See if it works, Red.
I tried your code with my modification... Works for me ... Strange ...
ok i found the problem i had in the options menu var's i dont know why but they made a conflict that was the reason why it didnt work