I am trying to make NPC’s that have a text box that displays a random canned message from a script. My only problem is that every NPC has this same script and each NPC has a different number of canned messages. So I need to write a script that can adapt to the number of canned messages to say that have been added to that individual script in the editor and pick random between those messages. Here is my script:
public class BasicNPCPrototype : MonoBehaviour
{
private bool knowBefore;
private int whichDialog;
private DialogueManager dialogueManager;
public int numberOfDialogues;
public Dialogue firstMeet;
public Dialogue dialogue1;
public Dialogue dialogue2;
// Use this for initialization
void Start ()
{
dialogueManager = FindObjectOfType<DialogueManager>();
}
// Update is called once per frame
void Update ()
{
}
public void Speak()
{
// Choose what to say
whichDialog = Random.Range(1, numberOfDialogues);
// If this NPC has never been talked to before
if(!knowBefore)
{
dialogueManager.StartDialogue(firstMeet);
knowBefore = true;
}
else
{
// Call the "StartDialogue" function in the DialogueManager and pass in our dialogue variable
dialogueManager.StartDialogue(dialogue1);
}
}
}
I need some way of being able to change the number of Dialogue variables in the editor and have the computer look at the number, put it into an int, and use it in Random.Range. But my biggest challenge will be creating the Dialogue variables in the editor and getting the computer to see it. Thanks.