Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class EntireGameManager : MonoBehaviour { public static int viewinglistitem = 0; public List<string> showingtext = new List<string>(); public GameObject thetext; void atl (string adding){ showingtext.Add (adding); } // Use this for initialization void Start () { showingtext.Add ("I love chicken boiis"); showingtext.Add ("I love chicken boisssis"); atl ("AND CHICKEN IS ALSO SUPER GOOD SO YEAH "); } // Update is called once per frame void Update () { string textofitem = showingtext[viewinglistitem]; GetComponent<Text>().text = textofitem; if (Input.GetKeyDown(KeyCode.Space)){ if (showingtext.Count - 1 > viewinglistitem) { viewinglistitem += 1; } else { Debug.Log("Last item of list reached"); } } } } on line 30 i dont know and i cant find out how to get the component of the "thetext" gameobject in line 12. does anyone know how to do this???
Make it thetext.GetComponent<.... You could also make thetext directly point to the Text component, and not need the GetComponent call at all: Code (csharp): public Text thetext; .... thetext.text = "Foo";
Another option could be, if you're not really using it as a GameObject (or less often than as a 'Text' type), simply change the variable type to Text, and drag n drop it again in the inspector.