This repository has been archived by the owner on Apr 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NPC classes refactoring to enable player AI interactions extensions
- Loading branch information
Showing
5 changed files
with
51 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using UnityEngine; | ||
using UnityEngine.Events; | ||
|
||
public abstract class NPC : MonoBehaviour | ||
{ | ||
public UnityEvent<string> OnSpeak; | ||
|
||
[SerializeField] | ||
private AudioSource audioSource; | ||
|
||
private void Awake() | ||
{ | ||
audioSource = GetComponent<AudioSource>(); | ||
} | ||
|
||
public virtual void Interact() | ||
{ | ||
OnSpeak?.Invoke(GetText()); | ||
audioSource.Play(); | ||
} | ||
|
||
protected virtual string GetText() | ||
{ | ||
return string.Empty; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
using UnityEngine; | ||
using UnityEngine.Events; | ||
|
||
public class NPCEnemy : MonoBehaviour | ||
public class NPCEnemy : NPC | ||
{ | ||
public UnityEvent<string> OnSpeak; | ||
public AudioSource audioSource; | ||
public string text = "I deal 10 physical damage ( •̀ᴗ•́ )و ̑̑ "; | ||
|
||
public void GetHit() | ||
public override void Interact() | ||
{ | ||
OnSpeak?.Invoke(text); | ||
audioSource.Play(); | ||
base.Interact(); | ||
|
||
FindObjectOfType<Player>().ReceiveDamaged(); | ||
} | ||
|
||
protected override string GetText() | ||
{ | ||
return text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
using UnityEngine; | ||
using UnityEngine.Events; | ||
|
||
public class NPCFriendly : MonoBehaviour | ||
public class NPCFriendly : NPC | ||
{ | ||
public UnityEvent<string> OnSpeak; | ||
public AudioSource audioSource; | ||
public string text = "Hi there. Look out for that KOBOLD on the other side!"; | ||
|
||
public void Talk() | ||
protected override string GetText() | ||
{ | ||
OnSpeak?.Invoke(text); | ||
audioSource.Play(); | ||
|
||
return text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters