How can I keep and remember all the characters in the dialogue/s and how can I insert a new one in the middle of the array?How can I decode HTML characters in C#?How can I get Id of inserted entity in Entity framework?C# IDisposable correct usage and callIf loop using timeSinceLevelLoad variableHow to fix this Unity error?An unhandled exception of type 'System.TypeInitializationException' occurred in RTEvents.exeHow can i use the bool variables in logical way when the character collide the box?Unity GUIText on Collision c#Wandering AI in unity C#control object rotation by mouse click in unity
How 象【しょう】 ( ≈かたち、 すがた、ようす) and 象【ぞう】 (どうぶつ) got to be written with the same kanji?
Is the order of words purely based on convention?
Why does my browser attempt to download pages from http://clhs.lisp.se instead of viewing them normally?
Why, even after his imprisonment, people keep calling Hannibal Lecter "Doctor"?
Is the mass of paint relevant in rocket design?
Can someone give the intuition behind Mean Absolute Error and the Median?
How can I indicate the first and the last reference number written in a page of the bibliography in the header of the page?
Are fuzzy sets appreciated by OR community?
Subverting the emotional woman and stoic man trope
Why did the Soviet Union not "grant" Inner Mongolia to Mongolia after World War Two?
Lost Update Understanding
My Project Manager does not accept carry-over in Scrum, Is that normal?
If a spaceship ran out of fuel somewhere in space between Earth and Mars, does it slowly drift off to Sun?
Would you write key signatures for non-conventional scales?
Is a Middle Name a Given Name?
Quick Yajilin Puzzles: Scatter and Gather
Does wetting a beer glass change the foam characteristics?
Does every piano need tuning every year?
I transpose the source code, you transpose the input!
A food item only made possible by time-freezing storage?
What does מעלה עליו הכתוב mean?
Why isn't there armor to protect from spells in the Potterverse?
Why is 6. Nge2 better, and 7. d5 a necessary push in this game?
Suffocation while cooking under an umbrella?
How can I keep and remember all the characters in the dialogue/s and how can I insert a new one in the middle of the array?
How can I decode HTML characters in C#?How can I get Id of inserted entity in Entity framework?C# IDisposable correct usage and callIf loop using timeSinceLevelLoad variableHow to fix this Unity error?An unhandled exception of type 'System.TypeInitializationException' occurred in RTEvents.exeHow can i use the bool variables in logical way when the character collide the box?Unity GUIText on Collision c#Wandering AI in unity C#control object rotation by mouse click in unity
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have 3 scripts:
The first one is the manager:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueManager : MonoBehaviour
public Text dialogueText;
public Text nameText;
public float sentencesSwitchDuration;
public bool animateSentenceChars = false;
public GameObject canvas;
public static bool dialogueEnded = false;
public DialogueTrigger trigger;
private Queue<string> sentence;
// Use this for initialization
void Start()
sentence = new Queue<string>();
public void StartDialogue(Dialogue dialogue)
canvas.SetActive(true);
nameText.text = dialogue.name;
sentence.Clear();
foreach (string sentence in dialogue.sentences)
this.sentence.Enqueue(sentence);
DisplayNextSentence();
public void DisplayNextSentence()
if (this.sentence.Count == 0)
EndDialogue();
return;
string sentence = this.sentence.Dequeue();
dialogueText.text = sentence;
StopAllCoroutines();
StartCoroutine(DisplayNextSentenceWithDelay(sentence));
public IEnumerator DisplayNextSentenceWithDelay(string sentence)
if (animateSentenceChars)
dialogueText.text = "";
foreach (char letter in sentence.ToCharArray())
dialogueText.text += letter;
yield return null;
yield return new WaitForSeconds(sentencesSwitchDuration);
DisplayNextSentence();
private void EndDialogue()
dialogueEnded = true;
if (trigger.dialogueNum == trigger.dialogue.Length)
canvas.SetActive(false);
Debug.Log("End of conversation.");
The second one is the trigger:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DialogueTrigger : MonoBehaviour
public Dialogue[] dialogue;
[HideInInspector]
public int dialogueNum = 0;
private bool triggered = false;
public void TriggerDialogue()
if (triggered == false)
if (FindObjectOfType<DialogueManager>() != null)
FindObjectOfType<DialogueManager>().StartDialogue(dialogue[dialogueNum]);
dialogueNum += 1;
triggered = true;
private void Update()
if (DialogueManager.dialogueEnded == true)
if (dialogueNum == dialogue.Length)
return;
else
FindObjectOfType<DialogueManager>().StartDialogue(dialogue[dialogueNum]);
DialogueManager.dialogueEnded = false;
dialogueNum += 1;
The last one is the dialogue:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Dialogue
public string name;
[TextArea(1, 10)]
public string[] sentences;
For example in the trigger script the array dialogue contains 3 dialogues.
The first one name is: Jhon the second Player the third Npc
The first one have 2 sentences the second have 5 sentences the last one have 1 sentence.
The problem is if in the editor I set the array of dialogues to 1 it will delete the other two. And if I will change it back to 3 it will add twice the same of the first one and will not remember the two others.
What I want to do is to add to the trigger script a global bool flag:
If true remember all the characters names and sentences if changing the dialogue array. If changing the array size higher or lower to 1 or 0 remember the characters and sentences of them.
If false don't remember the characters names and sentences if changed the dialogue array to 0 but if changed the dialogue array to 1 then remember the first one and don't remember the other two. And then if I change the dialogue array size to 3 again since the flag is false remember the first one and create two new empty dialogues.
The second problem I have is each time when I change the dialogue array size for example the size was 3 and I changed it now to 4 there is a new place in the end at the bottom. But is there a way to be able to decide to insert a new name to the chat for example in the middle of the array ? For example at the second place or third place and not always in the end ? In the editor in the inspector.
c# unity3d
add a comment
|
I have 3 scripts:
The first one is the manager:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueManager : MonoBehaviour
public Text dialogueText;
public Text nameText;
public float sentencesSwitchDuration;
public bool animateSentenceChars = false;
public GameObject canvas;
public static bool dialogueEnded = false;
public DialogueTrigger trigger;
private Queue<string> sentence;
// Use this for initialization
void Start()
sentence = new Queue<string>();
public void StartDialogue(Dialogue dialogue)
canvas.SetActive(true);
nameText.text = dialogue.name;
sentence.Clear();
foreach (string sentence in dialogue.sentences)
this.sentence.Enqueue(sentence);
DisplayNextSentence();
public void DisplayNextSentence()
if (this.sentence.Count == 0)
EndDialogue();
return;
string sentence = this.sentence.Dequeue();
dialogueText.text = sentence;
StopAllCoroutines();
StartCoroutine(DisplayNextSentenceWithDelay(sentence));
public IEnumerator DisplayNextSentenceWithDelay(string sentence)
if (animateSentenceChars)
dialogueText.text = "";
foreach (char letter in sentence.ToCharArray())
dialogueText.text += letter;
yield return null;
yield return new WaitForSeconds(sentencesSwitchDuration);
DisplayNextSentence();
private void EndDialogue()
dialogueEnded = true;
if (trigger.dialogueNum == trigger.dialogue.Length)
canvas.SetActive(false);
Debug.Log("End of conversation.");
The second one is the trigger:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DialogueTrigger : MonoBehaviour
public Dialogue[] dialogue;
[HideInInspector]
public int dialogueNum = 0;
private bool triggered = false;
public void TriggerDialogue()
if (triggered == false)
if (FindObjectOfType<DialogueManager>() != null)
FindObjectOfType<DialogueManager>().StartDialogue(dialogue[dialogueNum]);
dialogueNum += 1;
triggered = true;
private void Update()
if (DialogueManager.dialogueEnded == true)
if (dialogueNum == dialogue.Length)
return;
else
FindObjectOfType<DialogueManager>().StartDialogue(dialogue[dialogueNum]);
DialogueManager.dialogueEnded = false;
dialogueNum += 1;
The last one is the dialogue:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Dialogue
public string name;
[TextArea(1, 10)]
public string[] sentences;
For example in the trigger script the array dialogue contains 3 dialogues.
The first one name is: Jhon the second Player the third Npc
The first one have 2 sentences the second have 5 sentences the last one have 1 sentence.
The problem is if in the editor I set the array of dialogues to 1 it will delete the other two. And if I will change it back to 3 it will add twice the same of the first one and will not remember the two others.
What I want to do is to add to the trigger script a global bool flag:
If true remember all the characters names and sentences if changing the dialogue array. If changing the array size higher or lower to 1 or 0 remember the characters and sentences of them.
If false don't remember the characters names and sentences if changed the dialogue array to 0 but if changed the dialogue array to 1 then remember the first one and don't remember the other two. And then if I change the dialogue array size to 3 again since the flag is false remember the first one and create two new empty dialogues.
The second problem I have is each time when I change the dialogue array size for example the size was 3 and I changed it now to 4 there is a new place in the end at the bottom. But is there a way to be able to decide to insert a new name to the chat for example in the middle of the array ? For example at the second place or third place and not always in the end ? In the editor in the inspector.
c# unity3d
add a comment
|
I have 3 scripts:
The first one is the manager:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueManager : MonoBehaviour
public Text dialogueText;
public Text nameText;
public float sentencesSwitchDuration;
public bool animateSentenceChars = false;
public GameObject canvas;
public static bool dialogueEnded = false;
public DialogueTrigger trigger;
private Queue<string> sentence;
// Use this for initialization
void Start()
sentence = new Queue<string>();
public void StartDialogue(Dialogue dialogue)
canvas.SetActive(true);
nameText.text = dialogue.name;
sentence.Clear();
foreach (string sentence in dialogue.sentences)
this.sentence.Enqueue(sentence);
DisplayNextSentence();
public void DisplayNextSentence()
if (this.sentence.Count == 0)
EndDialogue();
return;
string sentence = this.sentence.Dequeue();
dialogueText.text = sentence;
StopAllCoroutines();
StartCoroutine(DisplayNextSentenceWithDelay(sentence));
public IEnumerator DisplayNextSentenceWithDelay(string sentence)
if (animateSentenceChars)
dialogueText.text = "";
foreach (char letter in sentence.ToCharArray())
dialogueText.text += letter;
yield return null;
yield return new WaitForSeconds(sentencesSwitchDuration);
DisplayNextSentence();
private void EndDialogue()
dialogueEnded = true;
if (trigger.dialogueNum == trigger.dialogue.Length)
canvas.SetActive(false);
Debug.Log("End of conversation.");
The second one is the trigger:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DialogueTrigger : MonoBehaviour
public Dialogue[] dialogue;
[HideInInspector]
public int dialogueNum = 0;
private bool triggered = false;
public void TriggerDialogue()
if (triggered == false)
if (FindObjectOfType<DialogueManager>() != null)
FindObjectOfType<DialogueManager>().StartDialogue(dialogue[dialogueNum]);
dialogueNum += 1;
triggered = true;
private void Update()
if (DialogueManager.dialogueEnded == true)
if (dialogueNum == dialogue.Length)
return;
else
FindObjectOfType<DialogueManager>().StartDialogue(dialogue[dialogueNum]);
DialogueManager.dialogueEnded = false;
dialogueNum += 1;
The last one is the dialogue:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Dialogue
public string name;
[TextArea(1, 10)]
public string[] sentences;
For example in the trigger script the array dialogue contains 3 dialogues.
The first one name is: Jhon the second Player the third Npc
The first one have 2 sentences the second have 5 sentences the last one have 1 sentence.
The problem is if in the editor I set the array of dialogues to 1 it will delete the other two. And if I will change it back to 3 it will add twice the same of the first one and will not remember the two others.
What I want to do is to add to the trigger script a global bool flag:
If true remember all the characters names and sentences if changing the dialogue array. If changing the array size higher or lower to 1 or 0 remember the characters and sentences of them.
If false don't remember the characters names and sentences if changed the dialogue array to 0 but if changed the dialogue array to 1 then remember the first one and don't remember the other two. And then if I change the dialogue array size to 3 again since the flag is false remember the first one and create two new empty dialogues.
The second problem I have is each time when I change the dialogue array size for example the size was 3 and I changed it now to 4 there is a new place in the end at the bottom. But is there a way to be able to decide to insert a new name to the chat for example in the middle of the array ? For example at the second place or third place and not always in the end ? In the editor in the inspector.
c# unity3d
I have 3 scripts:
The first one is the manager:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DialogueManager : MonoBehaviour
public Text dialogueText;
public Text nameText;
public float sentencesSwitchDuration;
public bool animateSentenceChars = false;
public GameObject canvas;
public static bool dialogueEnded = false;
public DialogueTrigger trigger;
private Queue<string> sentence;
// Use this for initialization
void Start()
sentence = new Queue<string>();
public void StartDialogue(Dialogue dialogue)
canvas.SetActive(true);
nameText.text = dialogue.name;
sentence.Clear();
foreach (string sentence in dialogue.sentences)
this.sentence.Enqueue(sentence);
DisplayNextSentence();
public void DisplayNextSentence()
if (this.sentence.Count == 0)
EndDialogue();
return;
string sentence = this.sentence.Dequeue();
dialogueText.text = sentence;
StopAllCoroutines();
StartCoroutine(DisplayNextSentenceWithDelay(sentence));
public IEnumerator DisplayNextSentenceWithDelay(string sentence)
if (animateSentenceChars)
dialogueText.text = "";
foreach (char letter in sentence.ToCharArray())
dialogueText.text += letter;
yield return null;
yield return new WaitForSeconds(sentencesSwitchDuration);
DisplayNextSentence();
private void EndDialogue()
dialogueEnded = true;
if (trigger.dialogueNum == trigger.dialogue.Length)
canvas.SetActive(false);
Debug.Log("End of conversation.");
The second one is the trigger:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DialogueTrigger : MonoBehaviour
public Dialogue[] dialogue;
[HideInInspector]
public int dialogueNum = 0;
private bool triggered = false;
public void TriggerDialogue()
if (triggered == false)
if (FindObjectOfType<DialogueManager>() != null)
FindObjectOfType<DialogueManager>().StartDialogue(dialogue[dialogueNum]);
dialogueNum += 1;
triggered = true;
private void Update()
if (DialogueManager.dialogueEnded == true)
if (dialogueNum == dialogue.Length)
return;
else
FindObjectOfType<DialogueManager>().StartDialogue(dialogue[dialogueNum]);
DialogueManager.dialogueEnded = false;
dialogueNum += 1;
The last one is the dialogue:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Dialogue
public string name;
[TextArea(1, 10)]
public string[] sentences;
For example in the trigger script the array dialogue contains 3 dialogues.
The first one name is: Jhon the second Player the third Npc
The first one have 2 sentences the second have 5 sentences the last one have 1 sentence.
The problem is if in the editor I set the array of dialogues to 1 it will delete the other two. And if I will change it back to 3 it will add twice the same of the first one and will not remember the two others.
What I want to do is to add to the trigger script a global bool flag:
If true remember all the characters names and sentences if changing the dialogue array. If changing the array size higher or lower to 1 or 0 remember the characters and sentences of them.
If false don't remember the characters names and sentences if changed the dialogue array to 0 but if changed the dialogue array to 1 then remember the first one and don't remember the other two. And then if I change the dialogue array size to 3 again since the flag is false remember the first one and create two new empty dialogues.
The second problem I have is each time when I change the dialogue array size for example the size was 3 and I changed it now to 4 there is a new place in the end at the bottom. But is there a way to be able to decide to insert a new name to the chat for example in the middle of the array ? For example at the second place or third place and not always in the end ? In the editor in the inspector.
c# unity3d
c# unity3d
asked Mar 28 at 18:11
Dubi DuboniDubi Duboni
4521 silver badge10 bronze badges
4521 silver badge10 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
I think that what you need is to use a List instead of an array. A list will allow you to insert a new record wherever you want and also have varying lengths with no problems.
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404294%2fhow-can-i-keep-and-remember-all-the-characters-in-the-dialogue-s-and-how-can-i-i%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think that what you need is to use a List instead of an array. A list will allow you to insert a new record wherever you want and also have varying lengths with no problems.
add a comment
|
I think that what you need is to use a List instead of an array. A list will allow you to insert a new record wherever you want and also have varying lengths with no problems.
add a comment
|
I think that what you need is to use a List instead of an array. A list will allow you to insert a new record wherever you want and also have varying lengths with no problems.
I think that what you need is to use a List instead of an array. A list will allow you to insert a new record wherever you want and also have varying lengths with no problems.
answered Mar 28 at 21:13
Martin BonniciMartin Bonnici
266 bronze badges
266 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404294%2fhow-can-i-keep-and-remember-all-the-characters-in-the-dialogue-s-and-how-can-i-i%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown