- Home /
How do I add NPCs?
I want to put an NPC (Non playable character) In the game.
Basically:
- I want to be able to click on the NPC
Function OnMouseClick() {
}
Have a GUI that pops up to chat
Be able to exit the GUI
Can anyone help me :-P
Answer by Jesse Anders · Dec 06, 2010 at 02:57 AM
For clicking on an object (that has a collider), look at OnMouseDown(). For the 'chat' interface, look into Unity's built-in GUI system (that's not the only way it can be done, but it's probably the most straightforward way).
Beyond that, I think you'll have better luck if you ask more specific questions (either here or on the forums).
Basically i just want to click on the object and have a GUI pop up, but when i do it keeps saying to call the "OnGUI" function. But when i put that in i cant click on the object.
You'll need to post some code and tell us exactly what errors you're getting. You can edit your post to include that information. Or, if you need more general and/or extensive help, you might try posting to the forums ins$$anonymous$$d.
All GUI must be called in the function OnGUI() make a boolean var and only run the GUI code if its true, etc.
Last comment: Dec 07, 2010.
On a side note, wow, a question beginning with "How do I". It's a miracle.
I'm on an ipad seems the hover function doesn't work very well, bring it up with UT not me
Answer by ShadowParallax · May 26, 2012 at 08:00 PM
What you could do, is this. This is in C# since I don't know how to use JavaScript but it shouldn't be too hard to convert to JavaScript.
bool openChat = false;
void OnMouseClick() {
openChat = true;
}
void OnGUI() {
if(openChat == true) {
//GUI Code here.
}
}
Your answer
Follow this Question
Related Questions
Raycast play animation1 and then animation2 1 Answer
How to create a gui button inside an if statement? 1 Answer
Inputing an Equation 0 Answers
How to click a 3d object in unity3d? 3 Answers
Simple Backpack "Pick up and drop" 1 Answer