Dialogue System Overlapping Problem

Hello,

I have written some code in JavaScript that is suppose to simulate dialogue between a player and a character when the player is in range of the character. It works fine when I attach the script to one character and assign all the variables, but when I attach the same script to a different character and fill in different dialogue for that character, the other characters dialogue can be seen through the current dialogue.

A few pictures to show problem. If image looks cut off just right click and open image in new tab:

Here is the code:

“InitiateDialogue.js”

Please respond and thanks!

if (talking)
there is your problem. this variable is static that means it is shared between all instances. when one instance sets it to true every instance of your script shows its dialogue.

if (Input.GetKeyDown (KeyCode.E))
you should not use input in OnGUI. use event.current or query input in update and set a variable which is then tested in ongui.

playerChoices1 = true;
playerChoices2 = false;
playerChoices3 = false;
playerChoices4 = false;
playerChoices5 = false;
playerChoices6 = false;
playerChoices7 = false;
you should create a structure and logic which handles stuff automatically as you don’t want to hard code all your dialogues.

there are some dialogue packages in the assetstore. maybe one of them could give you a smoother start.

Hello,

I had done what you said about how the “if(talking)” call was static and changed it to a normal variable. It had fixed my problem. Thank you very much! Also, my next move was going to be figuring out how to make it so that I don’t have to hard code dialogue in like you said.

Well, that fixed my problem so thanks!