I want to make a pick up counter with GUI text. Do I need to add the scrip to controller or to the GUI text itself?
If so, can anyone leave a few examples for me to work off of?
I started this script off of the GUI text itself…but is about as far as I can get…if is even right. I don’t know where to go from here to add this as a “pick up” counter. The reason I want to do this is because the standard UI text always leaves lines through my game even on play mode as shown in attachment.
using UnityEngine;
using System.Collections;
public class PickupCounter : MonoBehaviour {
public GUIText countText;
private int count;
// Use this for initialization
void Start ()
{
count = 0;
SetCountText ();
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pickup")) {
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString();
}
}
Those two lines look like they are part of the canvas overlay. But I see you have gizmos on. If you turn off gizmos, do those lines go away?
As far as your code goes, are you facing an issue? I assume you’re putting this on a player, and while generally that wouldn’t be where I would have a script keeping track of your counter and updating it, it would be ok if you’re trying to learn. Then you’ll just have to have some stuff with the proper tag and a trigger collider to collect it.
oh and don’t forget to drag the text box from the hierarchy into the slot in the inspector for this component (at the moment it won’t let you because Text and GUIText aren’t the same thing, but it will once the type is fixed).
I think he was trying to use GUIText because he thinks the gizmo lines are appearing in his game scene from the canvas overlay box. So yep, he’ll need to turn off gizmos (so he doesn’t see the lines) and then do your suggestion to just go back to the text component.