- Home /
Unity hangs on start when finding gameobject
I have spent hours on this problem. I reworked a dialogue script to try and make it accessible from other scripts, but have spent so long working around a myriad of problems. Please help me.
Here is the script with the function:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class textstep : MonoBehaviour { public void TextScroll(string text, float timebetweenletters) { GetComponent().text = text.Substring(0, 0); float timer = timebetweenletters; int letter = 1; while (!Input.GetKeyDown("space")) { timer -= Time.deltaTime; if (timer < 0 && letter != text.Length) { letter += 1; GetComponent().text = text.Substring(0, letter); timer = timebetweenletters; GetComponent().Play(); } } } }
and here is the script calling it:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class textstep : MonoBehaviour { public void TextScroll(string text, float timebetweenletters) { GetComponent().text = text.Substring(0, 0); float timer = timebetweenletters; int letter = 1; while (!Input.GetKeyDown("space")) { timer -= Time.deltaTime; if (timer < 0 && letter != text.Length) { letter += 1; GetComponent().text = text.Substring(0, letter); timer = timebetweenletters; GetComponent().Play(); } } } }
I have both the scripts on a text gameobject and I have the text gameobject on the textstep parameter of the script.
Oh gosh, it didn't add the line spaces. This looks like such a mess.