- Home /
Dialouge System [SOLVED]
Hello there! I am trying to create a dialogue system were everytime you press "W" it will go to the next dialouge. The problem I have encountered is that when I press W, it detects the press multiple times, and it instantly jumps to the last dialogue, before closing automatically.
Here is my current script:
void OnGUI(){
if(Dialog1){
if(GUI.Button (new Rect(500,550,520,120), "Oh, you're finally awake! My name is Robo. Can you tell me a bit about yourself?\n What's your name?"));
username = GUI.TextField ( new Rect (500, 530, 520, 20), username, 60);
}
if(Input.GetKey(KeyCode.W)&& Dialog1){
Dialog1 = false;
Dialog2 = true;
}
if(Dialog2){
if(GUI.Button (new Rect(500,550,520,120), "Oh, Hello " + username));
}
if(Input.GetKey(KeyCode.W)&& Dialog2){
Dialog2 = false;
Dia3 = true;
}
if(Dia3){
if(GUI.Button (new Rect(500,550,520,120), "I have a quest for you " + username + ".\n Find a key hidden somewhere around here, and bring it back to me. \n \n *To pick up something, stand close to it and press ''S''*"));
}
if(Dia3 && Input.GetKeyUp(KeyCode.W)){
Dia3 =false;
}
}
SOLVED: I solved it by changing Input.GetKeyDown to Input.GetKeyUp, and change between these two for every dialogue.
Still haven't figured it out. I removed dialog2, which fixed the problem, but if I want to end dialog2 by pressing ''w'' it will simply end the dialog at dialog 1 ins$$anonymous$$d of showing dialog2.
Answer by Multifred · May 26, 2015 at 03:58 AM
You should use GetKeyDown instead of GetKey.
As the doc says GetKeyDown "Returns true during the frame the user starts pressing down the key identified by name." and it seems that what you are looking for. It's the same for GetButton vs GetButtonDown or GetMouseButton vs GetMouseButtonDown
Yeah, I tried that too, I have seemed to figure it out though; It should work to put Input.Get$$anonymous$$eyDown, then Get$$anonymous$$eyUp, and change between each dialouge. It have worked to now. :)
Thanks for your answer though!