Hi there people.
I am an artist and not much of a programmer so please bare with me :3
Using the Lerpz scripts in the third person version has helped a lot for my game.
Now I need to talk to an NPC based mesh character after pressing a button.
This will be the same on every character NPC and to examine items and scenery, text with a GUI text bubble will show and the letters will display like typing on a keyboard until all the text is read or displayed.
However as simple as this is I also need a sound to play when there’s more text to be read and an idle listening animation should play and the NPC, depending on the importance of character, would play a talking animation to give the impression a conversation is going on.
The player never talks himself like in Ocarina of Time.
After the conversation is over, when all text is read, when the player presses a button a sound should play and it’s back to game-play.
Would someone be willing to give me a good sample script or more to help me get past this?
I would highly appreciate it :3
I don’t have a code example at hand, but I can explain the logic I used, and I am certain you can build something similar!
Our basis will be a script, lets call it NPCDialogue, that we will use on any object that needs to be interactive.
In your update() check for a mouse over event. There is a helper class for this, but remember your NPC will need a collider for it work. If the mouse is over the object, display a GuiElement showing the icon you want at the required location.
Then check for a click (or other keypress) event. If you’ve got a mouse-over and a click, then the player clicked on this object, so you can then initiate whatever GUI display and logic you like.
You might want to have a look at the typewriter script example on Unify for help in making the text appear.
Then put NPCDialogue onto any object that needs to be interactive.
If you expose the variables that contain the sounds, icons and whatever text should be displayed, then you can customise each NPC appropriately, directly in the inspector.
You could also build out and control the logic of each object using booleans, so:
if (talk) Talk();
if (container) GenerateLoot();
And so on.
Good luck with it!
Hey, I’m also trying to script a method for talking to NPCs. So far I’ve been able to get the game to detect when I mouse over the NPC and when I left-click on the NPC, but I’ve been having trouble getting the actual dialogue to pop up.
Here’s my code:
// Changes the color of the material while the mouse is over the mesh
function OnMouseOver ()
{
renderer.material.color = Color(1.5, 1.5, 1.5);
}
function OnMouseExit ()
{
renderer.material.color = Color(1, 1, 1);
}
// Detect left mouse click and print it in the debug log.
function OnGUI()
{
var click : Event = Event.current;
var talk = false;
if(click.button == 0 click.isMouse)
{
Debug.Log("Left Click");
talk = true;
}
if (talk == true)
{
GUI.Box (Rect (0,0,100,50), "Hello!");
}
}
Hi
Same I am looking for the same and also to be able to get in a plane as a passenger after speaking to to npc and paying.