Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Jonathan Grieve](https://uploads.teamtreehouse.com/production/profile-photos/601842/micro_twitterCover.png)
Jonathan Grieve
Treehouse Moderator 91,253 PointsChanging the Text based on number of flies caught
Hi, I'm up to date with the game now and I've managed to increment the score as shown in the video.
But I then got a bit daring and decided to try and change the text based on the incremented score. It's age old problem, "1 flies" doesn't make all that much much sense does it?
Here's the script I used to try and fix it.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreCounter : MonoBehaviour {
public static int score;
private Text scoreCounterText;
//Text is a special class provided by Unit not built into c#
void Start() {
score = 0;
scoreCounterText = GetComponent<Text> ();
}
void Update() {
//scoreCounterText.text = score + " Flies";
if (score == 1) {
scoreCounterText.text = score + " Fly";
} else {
scoreCounterText.text = score + " Flies";
}
}
}
i keep getting an error though and can't play the game. Any idea why? :)
1 Answer
![Jack Beauchamp](https://secure.gravatar.com/avatar/d3dfb93e26614ac6d35326fdb6b20c7b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jack Beauchamp
2,411 PointsTried your code it works fine, do mind sharing what the error is, I am guessing it is just a simple grammar error.
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsYes I just tested it just now. Must have been a bug creeped in to Unity that was solved by simply restarting Unity :-)