- Home /
 
GUIText problem
Hi. I've been making GUIText before and it worked just fine, and now I did everything as I used to do and it just won't work. It says "MissingComponentException: There is no 'GUIText' attached to the "Ark" game object, but a script is trying to access it." And there actually is a GUIText object attached to my character.
Here is my script:
using UnityEngine; using System.Collections; public class ArkMovement : MonoBehaviour { public float speed = 1f; public float speed2 = 4f; public GUIText countText; private int count;
 void Start ()
 {
     count = 0;
     SetCountText ();
     countText = GetComponent<GUIText> ();
 }
 void Update ()
 {
     if (Input.GetKey(KeyCode.LeftArrow))
     {
         transform.position += Vector3.left * speed * Time.deltaTime;
     }
     if (Input.GetKey(KeyCode.RightArrow))
     {
         transform.position += Vector3.right * speed * Time.deltaTime;
     }
     if (Input.GetKey(KeyCode.UpArrow))
     {
         transform.position += Vector3.up * speed2 * Time.deltaTime;
     }
     if (Input.GetKeyDown (KeyCode.LeftShift)) 
     {
         speed = 2f;
     }
     if (Input.GetKeyUp (KeyCode.LeftShift)) 
     {
         speed = speed = 1f;
     }
 }
 void OnTriggerEnter2D(Collider2D other) 
 {
     if (other.gameObject.tag == "PickUp")
     {
         other.gameObject.SetActive(false);
         count = count + 1;
         SetCountText ();
     }
 }
 
 void SetCountText ()
 {
     countText.text = "Count: " + count.ToString();
     Debug.Log("SetCount Called, Count: " + count.ToString());
 }
 
               }
And here is my player panel (ignore graphic mistakes it's due to resize in paint):

Your answer
 
             Follow this Question
Related Questions
Add text on top of a gameobject. What is the best way? 1 Answer
GUI text not showing in scene or game view 0 Answers
Draw GuiText on 2d tile sprite Like 2048 game 0 Answers
Display GUI Text 1 Answer
cannot drag script to player.Guitext error,cannot drag player script to the player in hierarchy 2 Answers