I’m looking to implement a point and click style dialogue system in my game. The idea would be to see an NPC, click on them and a box of dialogue options appear. Does anyone know a good way to implement this kind of thing? I’m having trouble getting ym head around it.
The most straightforward way to handle the UI aspect would probably be to use the built-in GUI system.
Other than that though, you’ll probably have to ask a more specific question. There are several parts to the problem you mention - detecting mouse clicks, handling the UI, managing dialog flow, etc. What part in particular do you need help with?
To be more specific, I was thinking about a GUI, one panel/box would hold, say, four selectable questions. There would be another box above it which would display text answers to the questions. The system would work by clicking on a character and the dialogue GUI (both boxes) appearing. It can be cleared from view by clicking outside of the GUI’s bounds.
Also (sorry for so many questions), I’m having a bit of trouble with my First Person Controller, in that the mouse isn’t centered when the game starts which means looking around can be a bit of a pain - is there any way to sort this out?
To clarify something about the GUI. The two things that are confusing me are, A) how to bring the Dialogue GUI up when a character has been clicked. (I know I can use OnMouseUp (), but I’m not sure what code I’d enter beneath it, i.e, so when the mouse has been clicked the GUI pops into view - would this just be “setVisible”?). B) Whether or not it will be possible to implement that ‘Answer’ box, where you can see the NPC response; I was thinking about creating an empty ‘Response’ String and a text box, then writing Switch statements that would change the string being displayed in the text box, depending on what question has been asked.
I created a quick GUI in Photoshop to use. The idea is that in the Questions box there will be say 3or 4 buttons with dialogue options. The Answers box will have a text box displaying a generic welcome, which will change when a Question Button is clicked. The whole GUI should only appear when an NPC is clicked on, and needs to disapear once the user has clicked outside of it.
I’m pretty sure I know how to set up the questions, what I don’t know how to do is the last part; controlling it’s visability with OnMouseUp.
Thanks for the reply. I took a look at your code but still couldn’t find what I was looking for unfortunately. I’m just looking for someway to toggle the visibility of the GUI I made using the mouse.
How do I create the GUI, though, This is the part I’m having trouble with; I understand how to make a GUI from scratch, but I don’t know how to reference a premade GUI texture in code. As I see it the code should look a little like this:
bool isClicked = false;
function OnGUI()
{
if(!isClicked) return; //Return the 2D texture for my GUI
//Underneath this I code in the buttons, etc.
}
function OnMouseUp()
{
isClicked = true;
}
Then there would be the code for clicking the exit button. I think I have the gist of it, I just need to know what line of code to use to call the texture.
I already have, as it happens. I still couldn’t find a solution to my problem: I’m not sure how to reference my custom made GUI image through code, or - having solved that - toggle it’s visibility via the mouse.
Well, you already posted some code that indicates you do in fact have an idea of how toggle the GUI’s visibility using the mouse.
As for the documentation, I think it covers all the controls that the GUI system supports, so you should be able to find what you’re looking for in there. (You might also check the scripting reference for the control functions, as most of them have multiple overloads.)
If you’re still having trouble with this, maybe you could try this. Forget about the mouse toggling for now, and just try to get the GUI on the screen the way you want it. If you have trouble with that, post your code and/or explain what exactly it is that you’re stuck on.
I think I’ve solved it, I’m going to get onto coding the solution in a bit. I didn’t realise you could use GUI.Skin and then drag and drop the skin in the properties bar on the left.
God I must be tired, I left off a matching }. Again though, I’m getting more errors. One that keeps popping up:
ArgumentException: You are not allowed to call get_guiTexture when declaring a variable.
Move it to the line after without a variable declaration.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
dialogueScript…ctor () (at Assets/Scripts/dialogueScript.js:2)
I’ve tried coding this so many different way, even leaving out the image altogether, but I still can’t get it to take my code.
Can someone help me out and show me what it is I’m doing wrong, cause I don’t get it, and for some reason I can’t even draw out a basic GUI; which was going to be my last resort.