- Home /
Confusing Logic (Just need some help with what goes where)
So my game has a tutorial... when you press any key at the start, the first Welcome GUI is replaced by your first instruction GUI, telling you what to do. Once you click the button "Continue", that GUI goes away and the game goes into action. Once you pick up an ammo box, as instructed, another GUI comes up and asks you to reload your ammo. Eventually, I will make it ask you to shoot the target, and then walk through the now open gate. Everything works, I just have my logic wrong, I think.
As many know, coding requires the ability to think logically and critically when making if() statements. I'm usually okay with this, but right now I'm stumped as to where my logic went wrong.
My problem starts when I hit the "Continue" Button. First of all, it does not disappear as it should... that may be a syntax problem, but I'm not sure. Once you click "Continue", both the button and the GUITexture it hovers over should disappear until the player picks up some ammo. Then, it should bring up another GUI. All of this happens, but the GUI button and Texture does not disappear when the button is clicked. You can even step onto the ammo box, picking it up, and cause the next GUI to come up... but the other one is still there and it totally messes up what the player should see. I've tried using booleans, as you might notice the vast amount of them in the variables section, to cause the GUI to disappear when the player starts up, but to no avail.
I apologize deeply for the mess of code in this script... I would very much appreciate any help that I can get with this.
(P.S. I noticed that on these forums people answer specifically to what you ask, offering no further information after that. I would be grateful if you include any errors that you might see in this script, potentially causing this glitch. If it's syntax or logic, or even typo, please.. don't hesitate to point it out. Thanks!)
My code:
#pragma strict
var StartG : GUITexture; //This is the background texture that the text lays over.
//It is used multiple times throughout the script for different messages to the player.
var StartG2 : GUITexture; //This is the "Welcome" message via a texture.
//It thanks the player for playing.. etc.
var TutG : GUITexture; //This is the first instruction given to the player.
//It just says to grab some ammo.
var TutG2 : GUITexture; //This is the second bit of instruction to the player.
// It just tells the player to reload with "R".
var ExG : GUITexture; //This hasn't been used yet, but it will be the message
//telling the player to exit through the now open gate.
var Char : GameObject; //This is an object used to deactivate/activate the player's gun,
//which should not be allowed to be used while the game is "paused" during a GUI message.
var Aim : GameObject; //This deactivates/activates part 1 of my mouselook script
var Aim2 : GameObject; //This deactivates/activates part 2 of my mouselook script
var Welcome : boolean; //This is used to make sure the first GUI doesn't over-power
//the other GUIs in the future, because the key input might cause issues and glitches.
var Tutorial : boolean = false; //This is the same as the first, though I do not
//remember where I used it.. perhaps I should look into this?
var ThatObj : GameObject; //This is the object that holds the script that is called to
//determine whether or not the player has stepped on the "AmmoBox" in question.
var Active : GameObject; //Just experimental: I was trying to see if I could make
//this object inactive when a GUI was deactivated, and in result activating another GUI.
var TutButton1 : boolean; //The button bool that you see in the first Info GUI.
var TutButton2 : boolean; //The button bool you see in the second Info GUI.
var Tut1 : boolean; //The bool used to activate the first info message.
var Started : boolean; //The bool used to show the welcome msg
var ThisBool : boolean; //Used to separate a function from an if() statement
function Start () {
Welcome = true;
}
function Update () {
if(TutButton1 == true) {
Time.timeScale = 1;
StartG.enabled = false;
Char.active = true;
Aim.GetComponent(MouseLook).enabled = true;
Aim2.GetComponent(MouseLook).enabled = true;
StartG2.enabled = false;
Welcome = true;
Debug.Log("TutButton1 has been pressed");
}
if(TutButton2 == true) {
Time.timeScale = 1;
StartG.enabled = false;
TutG.enabled = false;
Char.active = true;
Aim.GetComponent(MouseLook).enabled = true;
Aim2.GetComponent(MouseLook).enabled = true;
StartG2.enabled = false;
Debug.Log("TutButton2 has been pressed");
Destroy(TutG);
}
if(Tut1 == true) {
TutG.enabled = false;
StartG.enabled = true;
TutG2.enabled = true;
Time.timeScale = 0;
Char.active = false;
Aim.GetComponent(MouseLook).enabled = false;
Aim2.GetComponent(MouseLook).enabled = false;
}
if(Started == true) {
StartG2.enabled = false;
TutG.enabled = true;
Welcome = false;
if(TutG.enabled == true) {
ThisBool = true;
}
}
}
function OnGUI() {
if(Input.anyKeyDown && Welcome == true) {
Started = true;
}
if(ThisBool == true) {
if(GUI.Button (Rect (Screen.width * 0.5, Screen.height * 0.5,80,20), "Continue")) {
TutButton1 = true;
}
if(TutButton1 == true) {
TutG.enabled = false;
}
if(ThatObj.GetComponent(AmmoBox).TutBox == true) {
Tut1 = true;
}
if(Tut1 == true) {
if(GUI.Button (Rect (Screen.width * 0.5, Screen.height * 0.5,80,20), "Start")) {
TutButton2 = true;
}
}
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
show gui when look certain object 2 Answers
How do i make a texbox show and hide 1 Answer
How to Hide the GUI when time.scale = 1 again 1 Answer
Show GUI on collision 2 Answers