Update for Roll-a-ball tutorial gui point counter issue

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

public float speed;
public GUIText countText;
private int count;

void Start ()
{
count = 0;
}

void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis(“Horizontal”);
float moveVertical = Input.GetAxis(“Vertical”);

Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

rigidbody.AddForce(movement * speed * Time.deltaTime);
}

void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == “PickUp”)
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}

void SetCountText ()
{
countText.text = "Count: " + count.ToString();
}
}

I was following the tutorial on roll-a-ball but when I got to the GUI set up I’m not able to just create a GUI text and drag it to my playerController script as shown in the video. I only see the create UI text option but that makes a Canvas and I’m unable to drop that into the playerController script. Is the Video out of date and how can I get my GUI counting points?

Again? Don’t you people have google?

Here is a link to one of the answers.

Here is a link to google.

Sorry, that was harsher then needed. To use the UI you need add using UnityEngine.UI at the top of your script, and change the variable type from GUIText to Text. As in the following script.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class PlayerController : MonoBehaviour {

    public float speed;
    public Text countText;
    private int count;

    void Start ()
    {
        count = 0;
    }

    void FixedUpdate ()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

        rigidbody.AddForce(movement * speed * Time.deltaTime);
    }

    void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.tag == "PickUp")
        {
            other.gameObject.SetActive(false);
            count = count + 1;
            SetCountText();
        }
    }

    void SetCountText ()
    {
        countText.text = "Count: " + count.ToString();
    }
}

Maybe at some point we can convince someone to redo the video.

It really was harsher than needed. You’ve provided an excellent answer, why insult the people who asked a question?

You’ve also demonstrated that Google is no substitute for personal knowledge of a subject.

Thank you for your answer, though.

Yes thank you for your answer.
And I agree they need to update the video.
They need a step by step walkthrough with the current changes.

Thanks again!

1 Like

Thanks! This was really helpful.

All good. I do have to point out the the whole series has been updated recently to cover the changes in 5.x. That video is largely irrelevant now.