- Home /
I want am coding for an NPC i wanting it to interact with the player by speaking to him when he walk by but i can't find coding solutions. I need help.
I want to make the NPC Talk to the character by saying it's nice out today is it not when the player walks bye. Every time the player would walk bye the NPC would say hello after.I wanting a solution but i can't find any tutorials. I'm still looking but if any body can help me out it would be great. It's for a capstone event, and i have non playable character 3. It's your choice if you want to help me since people will be seeing our game at our capstone night. I'm nervous since its in either march or april. Plus otherstuff happening for our final exam. Help if you agree to it.
I would think a trigger would suit the situation best. With some sort of time sensitive cooldown. Something like
public AudioSource source;
public AudioClip[] clips;
public float cooldown;
private System.DateTime lastBark;
void Awake()
{
lastBark = System.DateTime.Now;
{
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
if ((DateTime.Now - lastBark).TotalSeconds > cooldown)
{
Bark();
}
}
}
void Bark()
{
source.playOneShot(clips[Random.Range(0, clips.Length)]);
lastBark = System.DateTime.Now;
}
Answer by logicandchaos · Jan 08, 2020 at 03:34 PM
I think what would work in this situation is a bark.. basically when a certain criteria is met the character says a line. https://www.youtube.com/watch?v=tAbBID3N64A I'm creating my own NPC Ai asset for sale on the asset store, but won't be ready for sometime, there are dialog managers and things on there as well too.
Your answer
Follow this Question
Related Questions
Talking to multiple NPC's 2 Answers
Clicking on object to teleport player? 1 Answer
NPC conversations- do I need to script my own system? 2 Answers
Rigidbody collision/interaction 2 Answers
Follow Player 2d 1 Answer