Search Unity

Ink - Displaying Messages with Time intervals

Discussion in 'Scripting' started by ilkebirsen, Jul 3, 2019.

  1. ilkebirsen

    ilkebirsen

    Joined:
    Jun 5, 2019
    Posts:
    1
    Hi there. I am working on text-based game and using Ink plugin. Basically i want to display the text lines and responses/answers of the story, with time intervals like in every 5 sec, like in the game LIFELINE or ZARYA. I have tried to use Invoke method but it stops the Unity so i guess there is an error on function that i use in the method. Here the code that i am trying to run;

    Code (CSharp):
    1.  
    2. using Ink.Runtime;
    3. using UnityEngine.UI;
    4.  
    5. void Awake ()
    6.     {
    7.         _inkStory = new Story (inkAsset.text);
    8.         storyNeeded = true;
    9.                  Invoke("Spawn", 5f);
    10.     }
    11.  
    12. void Update()
    13. {
    14.  while (_inkStory.canContinue)
    15.             {
    16.  if (_inkStory.currentChoices.Count > 0)
    17.            {
    18.                 //President variable
    19.                 int president = (int)_inkStory.variablesState["PRESIDENT"];
    20.  
    21.                 RemoveButtons();
    22.                 for (int ii = 0; ii < _inkStory.currentChoices.Count; ++ii)
    23.                {
    24.                    UnityEngine.UI.Button choice = Instantiate (button) as UnityEngine.UI.Button;
    25.                    choice.transform.SetParent (_choices.transform, false);
    26.                    choice.transform.Translate (new Vector2 (0, 0));
    27.  
    28.                    UnityEngine.UI.Text choiceText = choice.GetComponentInChildren<UnityEngine.UI.Text> ();
    29.                    choiceText.text = _inkStory.currentChoices [ii].text;
    30.  
    31.                    UnityEngine.UI.HorizontalLayoutGroup layoutGroup = choice.GetComponent <UnityEngine.UI.HorizontalLayoutGroup> ();
    32.  
    33.                    int choiceId = ii;
    34.                    choice.onClick.AddListener(delegate{ChoiceSelected(choiceId);});
    35. }
    36.            {
    37.  
    38.  
    39. void Spawn()
    40.     {
    41.         GameObject message = Instantiate(_line) as GameObject;
    42.         message.transform.SetParent(_content.transform);
    43.         Text storyText = _line.GetComponentInChildren<Text>();
    44.         storyText.transform.localPosition = new Vector2(422, -117);
    45.         storyText.text = _inkStory.Continue();
    46.     }


    "_line" is the prefab that i instantiate with every line of the story with some icon images as messages. And i wrap the text line to the text child of the prefab. That's the way i choosed to display every messages.

    Thanks for your interest.