- Home /
Question by
shafferchance · Jul 06, 2014 at 11:41 PM ·
buttonboolean
My first if statement is going through but then the gui button doesn't work afterwards. Can anyone explain or solve it please(bool broke)?
using UnityEngine;
using System.Collections;
public class shipStats : MonoBehaviour {
public TwoDController twoD;
public bullet bull;
public saveLoad sL;
public int damage = 0;
public int hull = 0;
public int gun = 0;
public int aExp;
public int level = 0;
private bool useMoney = true;
private bool useStuff = false;
private bool maxLevel = false;
public bool broke = false;
public bool toUps;
public string[] hullLevel = {"Iriduim Steel composite-$0","Meteoric Iron-$1000","Arudium-$2000"};
public string[] gunType = {"Gunpowder-0","Incendiary-$500","Engery-$1000"};
private float currency;
// Use this for initialization
void Start () {
currency = twoD.money;
aExp += twoD.eExp;
}
// Update is called once per frame
void Update () {
if(useMoney && useStuff){
useMoney = !useMoney;
useStuff = !useStuff;
}
switch(level){
case 0:
if(aExp >= 0)
level += 1;
break;
case 1:
if(aExp >= 200)
level += 1;
break;
case 2:
if(aExp >= 500)
level += 1;
break;
case 3:
if(aExp >= 1000)
level += 1;
break;
case 4:
maxLevel = true;
break;
}
}
void OnGUI () {
GUI.TextField(new Rect(400f,0f,100f,50f),"Balance " + currency + ".");
if(!toUps){
if(GUI.Button(new Rect(Screen.width/4f,Screen.height/4f,100f,100f),"Upgrade")){
Debug.Log("Button clicked");
toUps = true;
}
}
if(toUps) {
GUILayout.BeginArea(new Rect(Screen.width/4f + 50f,Screen.height/2f,1024f,1024f));
GUILayout.BeginVertical();
useMoney = GUILayout.Toggle(useMoney,"Use Money for purchasing");
useStuff = GUILayout.Toggle(useStuff,"Use stuff to upgarde");
hull = GUILayout.Toolbar(hull,hullLevel,GUILayout.Width (700f));
gun = GUILayout.Toolbar(gun,gunType,GUILayout.Width(700f));
GUILayout.EndVertical();
GUILayout.EndArea();
if(GUI.Button(new Rect(0f,0f,100f,50f),"back")){
sL.saveData ();
toUps = !toUps;
}
if(maxLevel)
GUI.Label(new Rect(Screen.width/3f,Screen.height/2f,500f,200f),"Congrats you have gotten to the maxuim level at this time.");
}
if(GUI.changed){
switch(hull){
case 0:
if(currency >= 0f)
twoD.health = 1000;
else
broke = true;
break;
case 1:
if(currency >= 1000f)
twoD.health = 2000;
else
broke = true;
break;
case 2:
if(currency >= 2000f)
twoD.health = 3000;
else
broke = true;
break;
}
switch(gun){
case 0:
if(currency >= 0f)
bull.damage = 30;
else
broke = true;
break;
case 1:
if(currency >= 500f)
bull.damage = 100;
else
broke = true;
break;
case 2:
if(currency >= 1000f)
bull.damage = 200;
else
broke = true;
break;
}
}
if(broke){
if(GUI.Button(new Rect(Screen.width/2,Screen.height/2,200f,50f),"You can't afford this.")){
broke = !broke;
}
}
}
}
Comment
Can you be more specific about what your are expecting to happen, and what actually is happening. As written your code is very difficult to read, and its difficult to figure out what you are trying to do.