- Home /
Creating a dialogue with Physics.OverlapSphere
I want to upgrade my dialogue system. right now I have a targeting system that ; if the target is selected it plays this line of code.
selectedTarget.GetComponent<FirstNarratorComplete>().DisplayMenu = true;
Now how can I make a system were I can do that for Physics.OverlapSphere without creating a script for each of the characters?
Here is what I have so far:
using UnityEngine; using System.Collections;
public class inRangToTalk : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Collider[] cols = Physics.OverlapSphere(transform.position, radius);
foreach (Collider col in cols){
if (col && col.tag == "Player"){
Quests script = col.GetComponent<Questst>();
if (script.QuestOne ==true){
}
if(Quests.QuestOne ==true) {
selectedTarget.GetComponent<FirstNarratorComplete>().DisplayMenu = true;
}
}
}
It looks like the OverlapSphere is only being used to check if the player is within radius
. If you have only 1 player, easier to just say if( (transform.position - player.position).sqr$$anonymous$$agnitude < radius*radius)
This sort of non-critical stuff can also be done in a Coroutine, running maybe 2ce/frame (if you run near someone, if may take up to 1/2-sec for them to "notice" you, which isn't a problem and is almost better that way.)
Your answer
Follow this Question
Related Questions
DIY Dialog System (type-writer effect) 1 Answer
How do I change the value of a tag with raycasting? 0 Answers
Problems with simple dialogue 0 Answers
GUI Pop-Up On Cube Collision 1 Answer
Strange NullReferenceException when drawing DragableWindow 0 Answers