- Home /
Two variables in a GUI Button?
Hello everyone,
I'm working in a GUI with three buttons, if I hit one button the other two or one came disabled, depending of the requirement.
Now I'm trying to use two Var "GUI.enabled = emble;" and " GUI.enabled = bate:" in a single GUI button.
If I use one var it works, but I can't use both...
I did try this, but without any success..
GUI.enabled = bate,emble;
If I use this, only the first works...
GUI.enabled = bate;
GUI.enabled = emble;
GUI.skin = Skin_battery;
if (GUI.Button(Rect(870,470,80,39),"")){
battery();
}
How I can use both, if I need two or one?
Please any help is more than welcome!
And this is my script GUI Buttons Script.
evar Skin_tool : GUISkin;
var Skin_battery : GUISkin;
var Skin_Disassemble : GUISkin;
var beep : AudioClip;
var bate = true;
var emble = true;
function OnGUI (){
////////////////////////////////////////
//BATTERY
GUI.enabled = emble;
GUI.skin = Skin_battery;
if (GUI.Button(Rect(870,470,80,39),"")){
battery();
}
//DISASSEMBLE
GUI.enabled = bate;
GUI.skin = Skin_Disassemble;
if (GUI.Button(Rect(870,512,80,80),"")){
disassemble();
}
//TOOL
GUI.enabled = bate;
GUI.skin = Skin_tool;
if (GUI.Button(Rect(870,345,80,80),"")){
}
}
function battery() {
if(bate) {
bate = !bate;
}
else {
bate = !bate;
}
}
function disassemble() {
if(emble) {
emble = !emble;
}
else {
emble = !emble;
}
}nter code here
Answer by CodeMasterMike · Jan 30, 2013 at 06:45 AM
If I understand you correctly, you want that the buttons are enabled/diabled depending on these two booleans being true/false?
GUI.enabled = bate,emble;
Doesn't work, since you have two different booleans tellig the GUI to be enabled or not.
GUI.enabled = bate;
GUI.enabled = emble;
Does work because the emble boolean overwrites whatever the bate boolean set before it.
Maybe you would want to something like this, instead:
private bool GetABooleanValue()
{
if(bate == false && emble == false)
{
return false;
}
else if(bate == false && emble == true)
{
return false;
}
else if(bate == true && emble == false)
{
return false;
}
else
{
return true;
}
}
function OnGUI ()
{
////////////////////////////////////////
//BATTERY
GUI.enabled = GetABooleanValue();
GUI.skin = Skin_battery;
if (GUI.Button(Rect(870,470,80,39),""))
{
battery();
}
// Rest of the code here...
}
Now you have four different options to disable/enable your buttons depending on what these two booleans are set to.
Good luck!
Thanks Code$$anonymous$$aster$$anonymous$$ike for your time and help. I did try your code but is not working. $$anonymous$$aybe I'm missing something?
Please take a look to the script.
Thanks Again!
var Skin_tool : GUISkin;
var Skin_battery : GUISkin;
var Skin_Disassemble : GUISkin;
var beep : AudioClip;
var bate = true;
var emble = true;
private bool GetABooleanValue(){
if(bate == false && emble == false){
return false;
}else if(bate == false && emble == true){
return false;
}else if(bate == true && emble == false){
return false;
}else{
return true;
}
}
function OnGUI (){
//BATTERY
GUI.enabled = GetABooleanValue();
GUI.skin = Skin_battery;
if (GUI.Button(Rect(870,470,80,39),"")){
battery();
}
//DISASSE$$anonymous$$BLE
GUI.enabled = bate;
GUI.skin = Skin_Disassemble;
if (GUI.Button(Rect(870,512,80,80),"")){
disassemble();
}
//TOOL
GUI.enabled = bate;
GUI.skin = Skin_tool;
if (GUI.Button(Rect(870,345,80,80),"")){
}
}
/////////////////////////////////////////////////
function battery() {
if(bate) {
bate = !bate;
}
else {
bate = !bate;
}
}
function disassemble() {
if(emble) {
emble = !emble;
}
else {
emble = !emble;
}
}
You shouldn't copy and paste. It was just a example code. You should change in the GetABooleanValue function so it returns the rigt values that you want.
I jus set the if-statements and the return values to any values, since I don't know what kind of result you want to get.
Use the GetABooleanValue function to check if emble and bate is true, or not.
And if one of them, both or none of them is true, return your boolean value if the button should be active, or not.
So look over the function and change it so it returns the values you want to have.
Below, it should be working. Battery is depending on emble, DISASSE$$anonymous$$BLE is depending on bate, and the TOOL is depending on both of them.
var Skin_tool : GUISkin;
var Skin_battery : GUISkin;
var Skin_Disassemble : GUISkin;
var beep : AudioClip;
var bate = true;
var emble = true;
private bool GetABooleanValue(){
if(bate == false && emble == false){
return true;
}else if(bate == false && emble == true){
return false;
}else if(bate == true && emble == false){
return false;
}else{
return true;
}
}
function OnGUI (){
//BATTERY
GUI.enabled = emble;
GUI.skin = Skin_battery;
if (GUI.Button(Rect(870,470,80,39),"")){
battery();
}
//DISASSE$$anonymous$$BLE
GUI.enabled = bate;
GUI.skin = Skin_Disassemble;
if (GUI.Button(Rect(870,512,80,80),"")){
disassemble();
}
//TOOL
GUI.enabled = GetABooleanValue();
GUI.skin = Skin_tool;
if (GUI.Button(Rect(870,345,80,80),"")){
}
}
/////////////////////////////////////////////////
function battery() {
if(bate == true) {
bate = false;
}
else {
bate = true;
}
}
function disassemble() {
if(emble == true) {
emble = false;
}
else {
emble = true;
}
}
Thanks Code$$anonymous$$aster$$anonymous$$ike for your help, Now is working :)
var Skin_tool : GUISkin;
var Skin_battery : GUISkin;
var Skin_Disassemble : GUISkin;
var beep : AudioClip;
var bate = true;
var emble = true;
private function GetABooleanValue(): boolean{
if(bate == false && emble == false){
return true;
}else{ if(bate == false && emble == true){
return false;
}else{
if(bate == true && emble == false){
return false;
}else{
return true;
}
}
}
}
function OnGUI (){
//BATTERY
GUI.enabled = emble;
GUI.skin = Skin_battery;
if (GUI.Button(Rect(870,470,80,39),"")){
battery();
}
//DISASSE$$anonymous$$BLE
GUI.enabled = bate;
GUI.skin = Skin_Disassemble;
if (GUI.Button(Rect(870,512,80,80),"")){
disassemble();
}
//TOOL
GUI.enabled = GetABooleanValue();
GUI.skin = Skin_tool;
if (GUI.Button(Rect(870,345,80,80),"")){
}
}
/////////////////////////////////////////////////
function battery() {
if(bate == true) {
bate = false;
}
else {
bate = true;
}
}
function disassemble() {
if(emble == true) {
emble = false;
}
else {
emble = true;
}
}
Your answer
Follow this Question
Related Questions
mouse displays GUI text when on objects 3 Answers
A node in a childnode? 1 Answer
Assigning two variables ? 1 Answer
HorizontalScrollbar not appearing in GUILayout.BeginScrollview C# 3 Answers
3D Button? 1 Answer