- Home /
Score text wont appear
Hello i was following the roll-a-ball tutorial and after i made the public text on my ball and dragged the text onto it,there is a problem. The text that i want to appear is shown but the iteration of score is not being shown.
public class Acc : MonoBehaviour
{
public Text capsuletext;
private int capsule;
public Text timertext;
private Rigidbody rb3d;
public GameObject changer;
// Start is called before the first frame update
void Start()
{
capsule = 5;
rb3d = GetComponent<Rigidbody>();
setcount();
}
void Update()
{
setcount();
transform.Translate(Input.acceleration.x, 0,0);
}
public void Jump()
{
rb3d.AddForce(0, 300, 0);
}
public void Rjump()
{
rb3d.AddForce(0, -300, 0);
}
void OnTriggerEnter(Collider collision)
{
if (collision.gameObject.CompareTag("Bound"))
{
SceneManager.LoadScene("Gameover");
}
else if (collision.gameObject.CompareTag("Capsule"))
{
collision.gameObject.SetActive(false);
capsule = capsule - 1; //the score of 5 that is suppose to reduce to 0 is not being shown
setcount();
}
}
void setcount()
{
capsuletext.text = "Remaining : " + capsule.ToString(); //THE "Remaining" IS BEING SHOWN
if (capsule <= 0)
{
changer.SetActive(true);
}
}
}
capsule.ToString()
is going to add something to that string whatever the value. So, so long as setcount()
is being called (it's not clear that you know this for sure), the string being passed to the text element does have an integer at the end.
If the integer's not being seen then most likely I$$anonymous$$O is that it's just be being truncated due to the size of the text element. You could check this very quickly by changing it to
capsuletext.text = capsule.ToString();
If that's the issue you've got several options, for example: increase the size of the text element, reduce the font size, make it use "best fit".
Do I understand correctly, you see a ball with the word "Remaining:" over it but no count? When you pause the game in editor and you select the text in the inspector, does it also just say "Remaining:"?
Yes sir it does it only shows "remaining" and not the numbers i want it to be like this Remaining : 5(this number keeps decreasing)
Answer by ShirazAkber · Oct 16, 2019 at 07:46 AM
Guys i got it working the problem was that i was using a font called "Rosbed" which didn't show the numbers when i changed it back to "Liberationsans" it worked perfectly. any idea why the other font doesn't show the score? @HappiiGamer @Bonfire-Boy Thank you so much.
If you download free fonts, sometimes you get a demo version that doesn't have all the characters. If you go back to where you got it from you may find that there's an option to buy the full font.
Ah yes, the font. It's always good to open the Font $$anonymous$$ap and see what Characters it has. I have had this problem with pixel fonts which often don't have the special characters. There are simple programs out there that allow you to add some of your own characters into the existing Font $$anonymous$$ap if you want to keep it in your project. Another side note, it's good to plan the fonts in advance in a project, as you might want to translate your game at some point into Japanese, for example, and you might realize the font you have is completely off.. Talking from experience.