Trying to solve this error An object reference is required for the non-static field, method, or property 'ShopManagerScript.crops'

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class ShopManagerScript : MonoBehaviour
{
    public int[,] peopleNames = new int[4, 4];
    public float crops;
    public Text CropsTxt;
    public static int goldObtained = 0;

    // public float Gold;
    // public Text gold;
    void Start()
    {
        CropsTxt.text = "Crops:" + crops.ToString();
        //people
        peopleNames[1, 1] = 1;
        peopleNames[1, 2] = 2;
        peopleNames[1, 3] = 3;

        //demands
        peopleNames[2, 1] = 10;
        peopleNames[2, 2] = 20;
        peopleNames[2, 3] = 30;

        //payment
        peopleNames[3, 1] = 0;
        peopleNames[3, 2] = 0;
        peopleNames[3, 3] = 0;
    }

    public void Sell()
    {
        GameObject ButtonRef = GameObject.FindGameObjectWithTag("Events").GetComponent<EventSystem>().currentSelectedGameObject;
        if (crops >= peopleNames[2, ButtonRef.GetComponent<ButtonInfo>().PersonID])
        {
            crops -= peopleNames[2, ButtonRef.GetComponent<ButtonInfo>().PersonID];
            peopleNames[3, ButtonRef.GetComponent<ButtonInfo>().PersonID]++;
            CropsTxt.text = "Crops:" + crops.ToString();
            ButtonRef.GetComponent<ButtonInfo>().PaymentTxt.text = peopleNames[3, ButtonRef.GetComponent<ButtonInfo>().PersonID].ToString();

        }
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;


public class Gold : MonoBehaviour
{
    public static int goldObtained = 0;
    public TMP_Text textNoCollected;
    public int goldAmount;

    // Start is called before the first frame update
   public void addGold()
    {
        ShopManagerScript.goldObtained += goldAmount;
        textNoCollected.text = "Gold : " + ShopManagerScript.goldObtained;
        if (ShopManagerScript.crops <1 )
        {
            goldAmount = 0;
        }
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

Hello.

First when posting an error and need a solution, you must say where is the error, not just the error code explanation… The error code says exactly where is the problem (example: CS(23,34) means line 23, character 34)


Second, Do not post all script, only relevant lines… (All Gold.Update is 100% unnecessary, and sure almost all variable declarations are also unecessary for the post)


Then about your error, the problem is that you are trying to acess a no static variable (A) from a static funciton (B). I could say which variables if gave the error line…) In your project, maybe there is only one static instance of B , and maybe ony one nonstatic (A) but it could be more of them, so Unity needs to know what instance of A you want to modify.

You need to specify with instance, to assign a specifyc object and component from the scene to read/edit the variable value.

Bye!