New UI displaying score

I dont know how to display my score with unitys new ui before i just made a gui text and added it to the script component on my player

public GUIText countText;

void OnTriggerEnter(Collider other) {

//if the object we collide with has the tag "PickUp we set its transform to inactive and 

adds to our count variable

		if (other.gameObject.tag == "PickUp") {

			//sets the  transform to inactive

			other.gameObject.SetActive(false);

			//adds one to our count 


			count += 1;

			//calls our function

			SetCountText();
		}

	}

	void SetCountText(){

	//creates a function that displays our score on the screem

	countText.text = "Score: " + count.ToString();
}

but this no longer worked and i cant find any tutorials

countText needs to be the Text component of the new GUI element containing the text, not the old GUIText. try to ensure that your code is formatted properly - it makes it easier to read. normally, i'd ignore your post because of that but i'm feeling generous today! ;)

–

whats wrong with it thats pretty simple to read

–

Seems like somebody fixed it since I commented.

–

If I've answered your question could you please accept my answer.

–

1 Answer

1

Include UnityEngine.UI in your includes.

Then make countText this: public Text countText;

The new UI uses a different type for all UI elements.