NullReferenceException: Object reference not set to an instance of an object textHolder+c__Iterator1.MoveNext () (at Assets/Script/textHolder.cs:27) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) textHolder:Start() (at Assets/Script/textHolder.cs:19)
The code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class textHolder : MonoBehaviour {
public string talking;
private TextManager TMan;
public float speed = 0.1f;
//public string fullText;
//private string currentText = "";
public string[] talkingLines;
// Use this for initialization
void Start () {
TMan = FindObjectOfType ();
StartCoroutine(ShowText());
}
IEnumerator ShowText(){
for (int i = 0; i < talkingLines.Length; i++) {
talking = talkingLines[i];
this.GetComponent ().text = talking;
yield return new WaitForSeconds (1);
}
}
// Update is called once per framea
void Update () {
}
void OnTriggerStay2D (Collider2D other)
{
if (other.gameObject.name == "Player")
{
if (Input.GetKeyUp (KeyCode.Space))
{
//TMan.ShowBox (talking);
if (!TMan.talkingActive)
{
TMan.talkingLines = talkingLines;
TMan.currentLine = 0;
TMan.showTalking ();
}
}
}
}
}
↧