x


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

more ▼

asked Dec 05 '10 at 09:49 PM

Nazukan 2 gravatar image

Nazukan 2
1 2 2 5

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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).

more ▼

answered Dec 06 '10 at 02:57 AM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

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.

Dec 07 '10 at 08:12 PM Nazukan 2

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 instead.

Dec 07 '10 at 09:33 PM Jesse Anders

All GUI must be called in the function OnGUI() make a boolean var and only run the GUI code if its true, etc.

Jan 23 at 10:02 PM landon91235

Last comment: Dec 07, 2010.

On a side note, wow, a question beginning with "How do I". It's a miracle.

Jan 23 at 10:08 PM Loius

I'm on an ipad seems the hover function doesn't work very well, bring it up with UT not me

Jan 24 at 01:54 AM landon91235
(comments are locked)
10|3000 characters needed characters left

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.
    }
}
more ▼

answered May 26 '12 at 08:00 PM

ShadowParallax gravatar image

ShadowParallax
15

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5087
x3795
x3693
x3335
x71

asked: Dec 05 '10 at 09:49 PM

Seen: 2729 times

Last Updated: Jan 24 at 01:54 AM