Q
Q
qsecretp2019-01-24 17:50:31
C++ / C#
qsecretp, 2019-01-24 17:50:31

Analyzed from and to. What's wrong?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Dialogs : MonoBehaviour {
  
  public bool skipText;
  public bool isPrint;
  public static string textMess;
  public GameObject Textdia;


  // Use this for initialization
  void Start () {
    StartCoroutine (TextPrint(Textdia.GetComponent<Text>(), textMess, 0.1f, skipText));
    //isPrint = false;
  }

  // Update is called once per frame
  void Update () {

    //Debug.Log(textMess);
  }


  public IEnumerator TextPrint(Text output, string input, float delay, bool skip)
  {
    if (isPrint) yield break;
    isPrint = true;
     for (int i=0; i < input.Length; i++) 
    {
      if (skip) { output.text = input; break; }
      output.text = input.Substring(0, i);
      yield return new WaitForSeconds(delay);
    }
    //Debug.Log (output);
  }


}

unity error:
NullReferenceException: Object reference not set to an instance of an object
Dialogs+c__Iterator1.MoveNext () (at Assets/scripts/UI/Dialogs.cs:31)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Dialogs:Start() (at Assets/scripts/UI/Dialogs.cs:16)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2019-01-24
@alexr64

for (int i=0; i < input.Length - 1; i++)
And you generally public IEnumerator TextPrintreturn nonsense. IEnumerator

D
Denis Gaydak, 2019-01-24
@MrMureno

Your textMess is equal to nothing .. you see.
not an empty string ... but straight ANYTHING.
and Nothing has a Length .
initialize the string at least ))
and in general, debugging works fine in the unit.
and nothing prevents Debug.Log Add and see what you send to the parameters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question