Creating a Score Display Error 00002

I am trying to create a score marker for my space shooter game. I ran into this error I have seen before, but I still don’t know how to fix it. Can someone help me?

The error is,

“Assets/Scripts/DestroyByContact.cs(7,17): error CS0246: The type or namespace name `GameController’ could not be found. Are you missing a using directive or an assembly reference?”

Here is my code

using UnityEngine;
using System.Collections;

public class DestroyByContact : MonoBehaviour
{
    public int scoreValue;
    private GameController gameController; //The error shows up here. 


    void Start ()
    {
        GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
        if (gameControllerObject != null)
        {
            gameController = gameControllerObject.GetComponent <GameController>();
        }
        if (gameController == null)
        {
            Debug.Log ("Cannot find 'GameController' script");
        }
    }


    void OnTriggerEnter2D (Collider2D other)
    {

        if (other.tag == "Boundary")
        {
            return;
        }

        Destroy (other.gameObject);
        Destroy(transform.gameObject);

        gameController.AddScore (scoreValue);
        Destroy(other.gameObject);
        Destroy(gameObject);
    }
}

Thank you for the help!

Try removing the private

1 Like

Also your GameObject shouldn’t be used for Controllers say instead:

void Start()
{
       gameController = GameObject.FindGameObjectsWithTag("tag").GetComponent<gameController>();
}
1 Like

Removing the private did not fix the issue and I fixed the code like you suggested. Thanks for the help! Do you have any other ideas?

The access modifier and usage of GetComponent have absolutely nothing to do with this error message.

Show us how your GameController class is defined.

1 Like

I think I may have just realized the problem after your comment. I don’t have a GameController class. Ill post again if I need more help, but thank you for the help!

Yeah that made the code work. I still have some more work to do, but changing class names around fixed the issue!