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 trialDaniel McTigue
1,017 PointsThe Name "scoreCounter" does not exist in the current context.
Even though scoreCounter is made public the notification continues to say it does not exist. Here are my two scripts for Fly pick up and Score Counter I probably have something misspelled. Thanks for the help. FlyPick up.cs using UnityEngine; using System.Collections;
public class FlyPickup : MonoBehaviour { [SerializeField] private GameObject pickupPrefab;
void OnTriggerEnter(Collider other) {
if (other.CompareTag ("Player")) {
Instantiate(pickupPrefab, transform.position, Quaternion.identity);
FlySpawner.totalFlies--;
//update the score
ScoreCounter.score++;
Destroy (gameObject);
}
}
}
ScoreCounter.cs using UnityEngine; using System.Collections; using UnityEngine.UI;
public class ScoreCounter : MonoBehaviour {
public static int score;
private Text scoreCounterText;
// Use this for initialization
void Start () {
score = 0;
scoreCounterText = GetComponent<Text> ();
}
// Update is called once per frame
void Update () {
scoreCounterText.text = scoe + " Flies";
}
}
4 Answers
Mike Wagner
23,559 PointsThe only thing that looks wrong, to me, is the typo in your ScoreCounter.cs script - "scoe" - but that would have probably been the name reported in console
Benjamin Gooch
20,367 PointsI'm having the same problem and I quadruple checked for typos.
If it helps at all, I'm using VIsual Studio to do my scripting. I haven't had any problems thus far, and even had no issues when using the FlySpawner reference earlier in this same script.
Anyone have an idea what might be going on here?
Benjamin Gooch
20,367 PointsSo, in Visual Studio, it reports this as an error, but Unity still runs just fine. It doesn't flag it as an issue when loading in the script, and the game works exactly as expected. Weird.
Glen Hayes
5,798 PointsSame problem here with Visual Studio but unity wont let me compile and enter game mode because of the error??
Henrique Prates
4,726 PointsI was having the error, what I think that fixed it was saving both script tabs that we edit in this video; it's possible that some people would forget to save both, since he only reminds to save it after working on one.
Daniel McTigue
1,017 PointsDaniel McTigue
1,017 PointsCan someone please help!