An object reference is required to access non-static member `ScoreManager1.scoreCount'

I think i need some help. My score and highscore is fine, but when I’m pressing the button it doesn’t add score.
In my old ScoreManager script the “score” were an int, and now its a float. I think that the problem is there, but since I’m a noob at programming I’m not sure, and don’t know how to fix it.

Problem lies in the DestroyOnClick script down below.

ScoreManager code

public class ScoreManager1 : MonoBehaviour {

    public Text scoreText;
    public Text highScoreText;

    public float scoreCount;
    public float highScoreCount;

    public float pointsPerSecond;

    public bool scoreIncreasing;

    // Use this for initialization
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {
        if (scoreIncreasing)
        {
            scoreCount += pointsPerSecond * Time.deltaTime;
        }
       
        if (scoreCount > highScoreCount)
        {
            highScoreCount = scoreCount;
        }

        scoreText.text = "Score: " + Mathf.Round(scoreCount);
        highScoreText.text = "HighScore: " + Mathf.Round(highScoreCount);
       
    }
}

Here is the DestroyOnClick script

public class DestroyOnClick : MonoBehaviour {

    private float timer = 0;
    public float X = 3;
    public int scoreValue = 10;

    public GameObject Button;
   

    void Update()
    {
        timer += Time.deltaTime;
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 500.0f) && hit.transform.gameObject != null)
            {
                Destroy(hit.transform.gameObject);
                ScoreManager1.scoreCount += scoreValue;  //This is the problem
            }
        }

        if (timer >= X) Destroy(Button);
    }
}

scoreCount either needs to be static or you need to access scoreCount through an instance of ScoreManager1

public static float scoreCount; of course, just one word off. Thank you for that :slight_smile:

In a similar case I tried to use an instance of the script I wanted to access but it didn’t work. I had to use an static variable, and it solved the problem.