Script Element Disappears After Pressing Play

As you can see where my mouse cursor is there is the text added

but after I press play, it disappears as shown below

Any help would be greatly appreciated!

Hi there. What is triggering the problem is the first line in your Start Function.

countText = GetComponent<Text> ();

It seems to me that your script is attached to the Player GameObject in the hierarchy, and obviously, the Player DOESN’T HAVE A TEXT COMPONENT.

what the sentence does, it to set the countText to the Text Component of your PLAYER gameObject. Since your player has no text, it returns null.

I think what you actually wanna to do is this:

countText = countText.GetComponent<Text> ();

However, since countText is already a Text, you don’t actually need to re-assign at all. It is simply safe for you to delete this line.

Hope my answer helps, and please feel free for further questions.

GL & HF!